Quote:
I have used button control to change the property values for custom control.
Button width and height property values are not changed.
Well ... that code doesn't use any variable values except the ClipRectangle you are passed which is the total size of the control drawing area. Everything else in there is a constant value, so I wouldn't expect anything to change, unless your external Button code is changing the actual width and height of the whole control.
So what does your button code do, and what effect did you expect it to have on your control?
BTW: If you use a
using
block, your Dispose is called for you when teh object goes out of scope:
using (Pen p = new Pen(Color.Black, 2))
{
Rectangle fillRect = new Rectangle(10, 10, 40, 40);
using (Brush b = new SolidBrush(Color.FromArgb(240, 240, 240)))
{
g.FillRectangle(b, fillRect);
g.DrawRectangle(p, e.ClipRectangle);
using (Brush black = new SolidBrush(Color.Black))
{
using (Font myFont = new Font("Segoe UI", 10, FontStyle.Regular))
{
g.DrawString(Text, myFont, black, new Point(4, 4));
}
}
}
}
But ... I'd create them outside the method in private static class level variables so there is only ever one of them created - it'll save time in your Paint method which is important as it has an effect of total performance of your app. And they don't need to be Disposed at all, so no Handles leaking around like your code has!