المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : drawing multi line



C# Programming
08-21-2009, 07:51 PM
I try to draw line with this code on a panel (I sent code only related to drawing). I can draw one line but if I want to draw multi line, there is an error like this: ArrgumentException was unhandled, Parameter is not valid.

Where is my fault?


private void panel1_Paint(object sender, PaintEventArgs e)
{


if (drawLine == true)
{
PictureBox PictureBox2 = new PictureBox();
int x1 = panel1.Width / 2;
int y1 = panel1.Height / 2;
PictureBox2.******** = new Point(x1, y1);
PictureBox2.Size = new System.Drawing.Size(50, 30);
PictureBox2.SizeMode = PictureBoxSizeMode.CenterImage;
panel1.Controls.Add(PictureBox2);

PictureBox2.Image = Image.FromFile(@"C:\warehouse.bmp");



for (int i = 0; i < MaxRows; i++)
{

PictureBox PictureBox1 = new PictureBox();
PictureBox1.Image = Image.FromFile(@"C:\retailer.bmp");
int x = coordinates[i, 0];
int y = coordinates[i, 1];

PictureBox1.Size = new System.Drawing.Size(25, 25);
PictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
PictureBox1.******** = new Point(x1 + x, y1 - y);
panel1.Controls.Add(PictureBox1);

Graphics g = e.Graphics;
Pen myPen = new Pen(Color.Black, 1);
g.DrawLine(myPen, x1, y1, x1+x, y1-y);
myPen.Dispose();
g.Dispose();

}
}
}



private void button1_Click(object sender, EventArgs e)
{
TakeValues();

drawLine = true;
panel1.Invalidate();
}