Click to See Complete Forum and Search --> : Graphics Help Please
SourSW
September 18th, 2005, 09:01 PM
I have two forms: MainForm and SubForm
MainForm will create & display the SubForm when a user clicks a button. In SubForm's load event, I draw a bunch of graphics. My problem is that the graphics never show. When I move my graphics code to the MainForm, and have it access SubForm's variables, the graphics appear. InvokeRequired comes back false. I'm stumped why I cannot draw the graphics from SubForm. Anyone have any ideas? Thanx.
jmcilhinney
September 19th, 2005, 01:29 AM
Obviously it's possible, but you must be using incorrect code. Without seeing what code you're using it's not really possible to know what the issue might be.
SourSW
September 19th, 2005, 04:31 PM
Here's the code from SubForm:
Public cG As Graphics
Public draw As New Pen(Color.Black, 3)
Public points As PointF()
Private Sub frmCG_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim index As Integer
ReDim points(5)
Me.cG = Me.pnlcG.CreateGraphics
For index = 0 To 5
points(index).X = (index + 1) << (index + 1)
points(index).Y = 20 * index
Next
Me.cG.DrawLines(Me.draw, Me.points)
End Sub
And Here's MainForm loading subForm:
Private WithEvents frmCG As formCG '//Globally Declared
Me.frmCG = New formCG '//Included in some other func before next one executes
Private Sub clbPopUps_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clbPopUps.SelectedIndexChanged
If (Me.clbPopUps.GetItemChecked(0)) Then
Me.frmCG.Show()
Else
Me.frmCG.Hide()
EndIf
End Sub
jhammer
September 19th, 2005, 04:59 PM
The form has a Paint event. You are passed a PaintEventArgs which contains a Graphics property.
This event is raised whenever the form needs to repaint itself.
You should use it to handle all GDI graphics.
Pass all the drawing to this event instead of Form_Load. It might solve your problem.
SourSW
September 19th, 2005, 05:30 PM
Thanx, that worked. I replaced my Graphics variable with the one supplied with the PaintEventArgs in my panel Paint event. I guess the graphics code in the form load was executing but because a paint event would be raised afterwards, it just simply overwrote the graphics.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.