TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Israel
702
1.3k
216.4k
Need to print my "panel"...
Aug 12 2015 1:45 PM
Hi,
I read these code and I need to print my panel but I receive this message:
Parameter is not valid
. The point of my bugg is on this line:
Bmp = new Bitmap("c:\desert.jpg")
The path is correct but I am not sure if something is not wrong:
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private MyPanel IPanel;
private Button[] Btns = new Button[2];
public Form1()
{
InitializeComponent();
IPanel = new MyPanel(this);
this.StartPosition = FormStartPosition.Manual;
IPanel.Location = new Point(10, 10);
this.ClientSize = new Size(IPanel.Width + 20, IPanel.Height + 100);
string[] BtnsTxt = {"Print", "Preview"};
for (int I = 0; I < Btns.Length; I++)
{
Btns[I] = new Button();
Btns[I].Text = BtnsTxt[I];
Btns[I].Top = IPanel.Bottom + 10;
Btns[I].Left = this.ClientSize.Width - (I + 1) * (Btns[0].Width + 20);
Btns[I].Click += ff_Click;
Btns[I].Parent = this;
}
}
private void ff_Click(object sender, EventArgs e)
{
if (((Button)sender).Text == "Preview")
{
IPanel.Preview();
}
else
{
IPanel.Print();
}
}
}
internal class MyPanel : Panel
{
internal Bitmap Bmp;
internal string[] T = { "RHC-IN-000089", "MUHOZI DAVID", "08-Oct-1991", "MALE", "PC069663" };
private PrintPreviewDialog PPDlg = new PrintPreviewDialog();
private PrintDocument PD = new PrintDocument();
public MyPanel(Form Parent)
{
this.Size = new Size(480, 340);
this.BackColor = Color.White;
Bmp = new Bitmap("desert.jpg");
//the bugg is pointed here
Bmp = Bmp.Clone(new Rectangle(85, 140, 80, 120), Bmp.PixelFormat);
this.Parent = Parent;
PD.OriginAtMargins = true;
PD.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
PD.DefaultPageSettings.PaperSize = new PaperSize("ICard", 480, 340);
PPDlg.Document = PD;
PD.PrintPage += PD_PrintPage;
}
public void Preview()
{
PPDlg.ShowDialog();
}
public void Print()
{
PD.Print();
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base.OnPaint(e);
DrawCard(e.Graphics);
}
public void PD_PrintPage(object sender, PrintPageEventArgs e)
{
DrawCard(e.Graphics);
}
public void DrawCard(Graphics G)
{
int X = 260;
int Y = 130;
G.DrawImage(Bmp, 75, 130);
for (int I = 0; I < T.Length; I++)
{
G.DrawString(T[I], this.Font, Brushes.Black, X, Y);
X = 200;
Y += 30;
}
Reply
Answers (
1
)
How do I get a hiddenfield id name in default.aspx.cs?
after end of the month i need to start the count from 1 in a