|
-
Mar 16th, 2004, 09:38 AM
#1
Thread Starter
Lively Member
Draw Lines on FormLoad??? [RESOLVED]
I am using the following code to draw a line (this will ultimately become a table):
Code:
Private Sub DrawLines()
Dim g As Graphics
Dim PenColor As New Pen(Color.Black)
Dim APoint As New Point(30, 350)
Dim BPoint As New Point(500, 350)
g = Me.CreateGraphics
g.DrawLine(PenColor, APoint, BPoint)
End Sub
This works fine as long as I call the sub from a click event, or a text change, etc. If I call it from a Form Load or Form Activate command, it won't draw the lines. I know the code is being executed because I put a MessageBox in there for testing, but the line just isn't being drawn. Any idea what's going on and how to fix it?
Thanks in advance
Last edited by Daywalker46410; Mar 16th, 2004 at 09:51 AM.
Joe Cody
Data Integration Engineer
Novaspect, Inc.
Elk Grove Village, IL
-
Mar 16th, 2004, 09:42 AM
#2
Hi.
The lines are actually drawn ok. But after the call to the sub, when Form_Load exits, the form is redrawn, erasing your lines.
Try drawing the lines from a button click again. Move the form halfways out of sight and then back in. You'll notice that half of your lines are gone.
This is because your lines are not part of the form, so when the form redraws, you lines are deleted.
To have your lines visible at all times, draw the lines in the Form_Paint event instead. Then use e.Graphics instead if CreateGraphics.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Mar 16th, 2004, 09:46 AM
#3
Member
Well this became almost a double, since I went to get coffee, while typing it... =)
Orig. post enclosed below:
Perhaps if you put your code in event: Form_Paint instead?
At least it worked when I tried it.
Im guessing the problem is that, in Form_Load the form isn't "painted" yet, which when you draw your line, and then Form_Load completes and "over-draws" your line?
Any one else that think differently or knows for sure is welcome to comment. =)
-
Mar 16th, 2004, 09:50 AM
#4
Member
Re: Draw Lines on FormLoad???
Originally posted by Daywalker46410
I am using the following code to draw a line (this will ultimately become a table):
Code:
Private Sub DrawLines()
Dim g As Graphics
Dim PenColor As New Pen(Color.Black)
Dim APoint As New Point(30, 350)
Dim BPoint As New Point(500, 350)
g = Me.CreateGraphics
g.DrawLine(PenColor, APoint, BPoint)
End Sub
This works fine as long as I call the sub from a click event, or a text change, etc. If I call it from a Form Load or Form Activate command, it won't draw the lines. I know the code is being executed because I put a MessageBox in there for testing, but the line just isn't being drawn. Any idea what's going on and how to fix it?
Thanks in advance
Did you try putting that in the form's paint event?
Edit: I didnt see Pax already had it.
-
Mar 16th, 2004, 09:50 AM
#5
Thread Starter
Lively Member
That got it. Thanks, guys.
Joe Cody
Data Integration Engineer
Novaspect, Inc.
Elk Grove Village, IL
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|