A
Ashutosh
Hi,
I am trying to create a custom control in which I have to display my custom
data. The custom control is placed on a form and docked completely. When I
have the following code for the custom control, it doesn't re-paint all the
data when I re-size the form vertically at run time. If I switch to other
window and use ALT-TAB to switch back to my form, everything works fine.
The code for my custom control is
public partial class CustomControl1 : Control
{
Dictionary<int, string> data = new Dictionary<int, string>();
public CustomControl1()
{
InitializeComponent();
for (int i = 1; i <= 40; i++)
{
data[i * 20] = "This is a sample text for line number " +
i.ToString();
}
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
foreach (int y in data.Keys)
{
if (e.ClipRectangle.Y <= y && (e.ClipRectangle.Y +
e.ClipRectangle.Height) >= y)
{
e.Graphics.DrawString(data[y], SystemFonts.DefaultFont,
SystemBrushes.ControlText, new PointF(20, y));
}
}
}
}
I am actually confused with the the usage of ClipRectangle. Please advice.
Thanks & Regards,
Ashu
I am trying to create a custom control in which I have to display my custom
data. The custom control is placed on a form and docked completely. When I
have the following code for the custom control, it doesn't re-paint all the
data when I re-size the form vertically at run time. If I switch to other
window and use ALT-TAB to switch back to my form, everything works fine.
The code for my custom control is
public partial class CustomControl1 : Control
{
Dictionary<int, string> data = new Dictionary<int, string>();
public CustomControl1()
{
InitializeComponent();
for (int i = 1; i <= 40; i++)
{
data[i * 20] = "This is a sample text for line number " +
i.ToString();
}
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
foreach (int y in data.Keys)
{
if (e.ClipRectangle.Y <= y && (e.ClipRectangle.Y +
e.ClipRectangle.Height) >= y)
{
e.Graphics.DrawString(data[y], SystemFonts.DefaultFont,
SystemBrushes.ControlText, new PointF(20, y));
}
}
}
}
I am actually confused with the the usage of ClipRectangle. Please advice.
Thanks & Regards,
Ashu