Z
Zachary Turner
I have an object derived from UserControl which I place on my form.
The UserControl handles the OnPaint event for itself, so that I can do
custom drawing of my control. I have a problem with this custom
drawing, I'm hoping someone can provide some insight.
I placed my control on the page about 100 times using a loop similar to
the following:
System.Collections.Generic.List<System.Windows.Forms.Control> Controls
= new System.Collections.Generic.List<System.Windows.Forms.Control>();
for (int Row = 0; Row < Height; ++Row)
for (int Col = 0; Col < Width; ++Col)
Controls.Add(new MyControl()); //Other initialization (size,
position, etc) is handled, just snipped for clarity
this.Panel.SuspendLayout();
this.Panel.Controls.AddRange(Controls.ToArray());
this.Panel.ResumeLayout(false);
In the OnPaint event of MyControl, I do the following:
private void MyControl_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.DrawLine(LinePen, this.Location, this.Location +
this.Size);
}
The problem is, the line only gets drawn on the very first control I
placed onto the page. I can verify that the other controls are
actually having their OnPaint handler called and that this.Location and
this.Size are correct, but I just don't see the line get drawn. Is
there something obvious I'm missing?
Thanks
The UserControl handles the OnPaint event for itself, so that I can do
custom drawing of my control. I have a problem with this custom
drawing, I'm hoping someone can provide some insight.
I placed my control on the page about 100 times using a loop similar to
the following:
System.Collections.Generic.List<System.Windows.Forms.Control> Controls
= new System.Collections.Generic.List<System.Windows.Forms.Control>();
for (int Row = 0; Row < Height; ++Row)
for (int Col = 0; Col < Width; ++Col)
Controls.Add(new MyControl()); //Other initialization (size,
position, etc) is handled, just snipped for clarity
this.Panel.SuspendLayout();
this.Panel.Controls.AddRange(Controls.ToArray());
this.Panel.ResumeLayout(false);
In the OnPaint event of MyControl, I do the following:
private void MyControl_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.DrawLine(LinePen, this.Location, this.Location +
this.Size);
}
The problem is, the line only gets drawn on the very first control I
placed onto the page. I can verify that the other controls are
actually having their OnPaint handler called and that this.Location and
this.Size are correct, but I just don't see the line get drawn. Is
there something obvious I'm missing?
Thanks