P
Peter Row
Hi,
I've started work on my own control some parts of which use standard
controls, others I need to draw on my controls surface to get the display
output I require, however....
I seem to be stupid or missing the point. I used DrawString( ) as a simple
test but I cannot get it to work at all unless I handle my custom controls
Paint event.
So for example if I say in the Paint event handler:
e.Graphics.DrawString("2006", this.Font, Brushes.Black, 50 , 2);
Then I see the text "2006" painted at coordinates 50, 2 on my control
as I'd expect.
HOWEVER....
If I simply have a method which says:
private void MyTestMethod( )
{
using (Graphics g = this.CreateGraphics( ))
{
g.DrawString("2006, this.Font, Brushes.Black, 50, 2);
}
}
I call the method and get absolutely nothing output, which is not what I
expect.
What the hell is going on?
What is the point of having a method on a control called CreateGraphics()
when you seemly can't use the object it returns to draw anything with it?
I am obviously missing something but I just can't see what that is, I looked
at a few examples of DrawString() on the net and they also seem to do it
within the confines of a Paint() event handler.
I probably could do what I need to do for my control in the Paint() event
handler but this is bugging me now and I have to know what I am doing
wrong or what I am misunderstanding.
Thanks for any help given,
Peter
I've started work on my own control some parts of which use standard
controls, others I need to draw on my controls surface to get the display
output I require, however....
I seem to be stupid or missing the point. I used DrawString( ) as a simple
test but I cannot get it to work at all unless I handle my custom controls
Paint event.
So for example if I say in the Paint event handler:
e.Graphics.DrawString("2006", this.Font, Brushes.Black, 50 , 2);
Then I see the text "2006" painted at coordinates 50, 2 on my control
as I'd expect.
HOWEVER....
If I simply have a method which says:
private void MyTestMethod( )
{
using (Graphics g = this.CreateGraphics( ))
{
g.DrawString("2006, this.Font, Brushes.Black, 50, 2);
}
}
I call the method and get absolutely nothing output, which is not what I
expect.
What the hell is going on?
What is the point of having a method on a control called CreateGraphics()
when you seemly can't use the object it returns to draw anything with it?
I am obviously missing something but I just can't see what that is, I looked
at a few examples of DrawString() on the net and they also seem to do it
within the confines of a Paint() event handler.
I probably could do what I need to do for my control in the Paint() event
handler but this is bugging me now and I have to know what I am doing
wrong or what I am misunderstanding.
Thanks for any help given,
Peter