Link to home
Start Free TrialLog in
Avatar of IT_Steve
IT_Steve

asked on

When does the DrawString method fire?

I am trying to use the DrawString method to display data in a label. Why will it onlt display after I clock ok to my messagebox ? I want it to display on formload. Please check out my code example. I am using VB.NET 2003. Thank you.

 '  A font for the standard size text:
        Dim fnt As Font = New Font("Microsoft Sans Serif", 8, FontStyle.Bold)

        '  A Brush to write the text:
        Dim b As Brush = New SolidBrush(Color.Black)
        '  Graphics objects
        Dim lgNH3 As Graphics = lblNH3.CreateGraphics

        MessageBox.Show("HUH?")
        Dim strNH As String = "What the..?"
        lgNH3.DrawString(strNH, fnt, b, 1, 1)
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of IT_Steve
IT_Steve

ASKER

Thank you Idle_Mind . Your solution works for me. Why did my original way behave as it did?
Because it is rare when CreateGraphics() should actually be used with a Control...since when the control refreshes itself, whatever you drew gets erased.

CreateGraphics() does not give you a persistent drawing surface.
Thank you for the explanation. The points are yours!
Steve