I am working with OpenGl (Tao Framework) on vb.net. Now, I know that I've implemented opengl correctly but I'm not actually sure where the problem lies with my code. Here is the best explanation of the problem I can come up with.
Given: The application I'm working with works perfectly in VB6 but in vb.net I've had to make changes to the UI portion of the code. Most pertinent to the problem at hand is that calls to the paint method of a picturebox can no longer be called as easily. I've had to replace calls to the paint method such as
with
.
The application I'm working on has a main form called frmbackground and it has a picturebox control called pctanimate on which I have attached the opengl graphics context (sorry if my terminology is incorrect).
When I rightclick on pctanimate, a menu pops up from which I can select to open(show and focus on) a form called frmgraphics in which I can change some graphics "properties" in pctanimate. When frmgraphics is displayed on the screen, frmbackground is disabled. There are three buttons in frmgraphics: apply, done, and cancel.
One last thing you should know: The default color of pctanimate is black. But the graphics that should always be shown are a white grid on a black background.
Problem: (In frmgraphics) Whenever I hit apply I lose the graphics on the screen and when I hit done (frmgraphics.close is called after calling frmbackground.enable = true) the graphics come back but the portion of the screen on which the frmgraphics was visible has not been painted. So when I hit done there is a black rectangle where frmgraphics used to be. There is no obvious problem with my paint event because when I hit apply (in frmgraphics) I lose the graphics but if I then move frmgraphics to another position on the screen pctanimate is correctly painted with the correct graphics(ie a grid) objects (ie no black rectangles result). How can I correct this problem?
Sample code:
This is called first as initiated by pressing the apply button on the frmgraphics form.
The next function to be called is frmbackground_paint
The debugger loops in frmbackground_paint (i'm guessing because I'm trying to step through every time visual studio tries to display the form as it debugs). After stepping out of debugging pctanimate now is all black and I have lost the graphics (frmgraphics is not closed by clicking apply). If I where to move the form frmgraphics, however, the graphics (ie the grid) re-appears.
The sequence of subroutines that fire when I step through the program after clicking done on frmgraphics is:
First:
then
then
I then end up back at frmbackground_paint and looping there until I step out of debug mode. After exiting debug mode the form frmgraphics is no longer visible but there is a black rectangle in the graphics grid where the form used to be. Opening any other form and moving it slightly will cause the pctanimate to repaint itself and as a result draw the complete grid without any problems.
I believe the problem occurs because I have not understood fully the sequence of paint events that are initiated by windows and how vb.net handles them. Any ideas as to where the problem may lie would be greatly appreciated.
Thank you for your time.
Given: The application I'm working with works perfectly in VB6 but in vb.net I've had to make changes to the UI portion of the code. Most pertinent to the problem at hand is that calls to the paint method of a picturebox can no longer be called as easily. I've had to replace calls to the paint method such as
Code:
frmBackground.PctAnimate_Paint(Nothing, New System.Windows.Forms.PaintEventArgs(Nothing, Nothing))
Code:
frmbackground.pctanimate.refresh
The application I'm working on has a main form called frmbackground and it has a picturebox control called pctanimate on which I have attached the opengl graphics context (sorry if my terminology is incorrect).
When I rightclick on pctanimate, a menu pops up from which I can select to open(show and focus on) a form called frmgraphics in which I can change some graphics "properties" in pctanimate. When frmgraphics is displayed on the screen, frmbackground is disabled. There are three buttons in frmgraphics: apply, done, and cancel.
One last thing you should know: The default color of pctanimate is black. But the graphics that should always be shown are a white grid on a black background.
Problem: (In frmgraphics) Whenever I hit apply I lose the graphics on the screen and when I hit done (frmgraphics.close is called after calling frmbackground.enable = true) the graphics come back but the portion of the screen on which the frmgraphics was visible has not been painted. So when I hit done there is a black rectangle where frmgraphics used to be. There is no obvious problem with my paint event because when I hit apply (in frmgraphics) I lose the graphics but if I then move frmgraphics to another position on the screen pctanimate is correctly painted with the correct graphics(ie a grid) objects (ie no black rectangles result). How can I correct this problem?
Sample code:
This is called first as initiated by pressing the apply button on the frmgraphics form.
Code:
Private Sub buttonApply_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles ApplyButton.Click
Dim k, i, j, KTemp As Integer
Dim IAnimateModeT As Integer
Dim DD As Double
Dim Str1 As Double
Dim Str2 As String
Dim DDC(3) As Double
frmBackground.PctAnimate.BackColor = Picture1.BackColor
'frmBackground.PctAnimate_Paint(Nothing, New System.Windows.Forms.PaintEventArgs(Nothing, Nothing))
frmBackground.PctAnimate.Refresh()
ScreenColor = SelectedColor
GridColor = GridColor1
For i = 1 To 3
AXColor(i) = AxisColor(i)
Next i
If Check1.CheckState = 1 Then
IGridShow = 1
Else
IGridShow = 0
End If
If Check2.CheckState = 1 Then
IAxesShow = 1
Else
IAxesShow = 0
End If
GridSpace = Combo1.SelectedIndex + 1
GridThickness = Combo2.SelectedIndex + 1
AxesLength = Combo3.SelectedIndex + 1
AxesThickness = Combo4.SelectedIndex + 1
'Camera
DDC(1) = CDbl(Text1.Text) - CDbl(Text4.Text)
DDC(2) = CDbl(Text2.Text) - CDbl(Text5.Text)
DDC(3) = CDbl(Text3.Text) - CDbl(Text6.Text)
k = 0
For i = 1 To 3
If System.Math.Abs(DDC(i)) < 0.0001 Then k = k + 1
If k = 2 Then
Mss(1) = "Wrong selection of the camera parameters."
Mss(2) = CStr(MsgBoxStyle.OkOnly)
Mss(3) = "Sams: Data Error"
Call ErrMess()
Exit Sub
End If
Next i
CamLx = CDbl(Text1.Text)
CamLy = CDbl(Text2.Text)
CamLz = CDbl(Text3.Text)
CamPx = CDbl(Text4.Text)
CamPy = CDbl(Text5.Text)
CamPz = CDbl(Text6.Text)
CamUpx = CDbl(Text7.Text)
CamUpy = CDbl(Text8.Text)
CamUpz = CDbl(Text9.Text)
DD = (CamUpx ^ 2 + CamUpy ^ 2 + CamUpz ^ 2) ^ 0.5
CamUpx = CamUpx / DD
CamUpy = CamUpy / DD
CamUpz = CamUpz / DD
CameraFovy = CDbl(Text11.Text)
ICameraFollow = Combo5.SelectedIndex
IBodyLook = Combo6.SelectedIndex
ICameraTranslate = Check3.CheckState
ICameraRotate = Check4.CheckState
If ICameraFollow = 0 Then
ICameraTranslate = 0
ICameraRotate = 0
End If
IPreviousCameraGraham = ICameraGraham
'Animation
AnimationSpeed = (10 - Slider1.Value) * 5
FrameSteps = Int(CDbl(Text10.Text)
End Sub
Code:
Private Sub frmBackground_Paint(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
If Err.Number <> 0 Then MessageBox.Show("Error Number: " & Err.Number.ToString & ". Error Source: " & Err.Source.ToString & ". This is error in paint 1")
If VB6.PixelsToTwipsX(Me.Width) <= 0.6 * VB6.PixelsToTwipsX(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width) Then _
Me.Width = VB6.TwipsToPixelsX(0.6 * VB6.PixelsToTwipsX(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width))
If VB6.PixelsToTwipsY(Me.Height) <= 0.6 * VB6.PixelsToTwipsY(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height) Then _
Me.Height = VB6.TwipsToPixelsY(0.6 * VB6.PixelsToTwipsY(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height))
If IUTL = 0 And NOC(6) = 0 Then
With PctAnimate
.Width = Me.Width
.Height = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(StatusBar1.Top) - VB6.PixelsToTwipsY(Toolbar1.Height))
.Left = 0
.Top = Toolbar1.Height
End With
Else
With SamsTree1
.Width = VB6.TwipsToPixelsX(0.177 * VB6.PixelsToTwipsX(Me.Width))
.Height = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(StatusBar1.Top) - VB6.PixelsToTwipsY(Toolbar1.Height))
.Left = VB6.TwipsToPixelsX(0.82 * VB6.PixelsToTwipsX(Me.Width))
.Top = Toolbar1.Height
'.Size = New System.Drawing.Size(100, 100)
'.Location = New System.Drawing.Point(200, 20)
'.Anchor = AnchorStyles.Right Or AnchorStyles.Top Or AnchorStyles.Bottom
End With
With PctAnimate
'.Width = 0.81 * Me.Width
.Width = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(Me.Width) - VB6.PixelsToTwipsX(SamsTree1.Width))
.Height = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(StatusBar1.Top) - VB6.PixelsToTwipsY(Toolbar1.Height))
.Left = 0
.Top = Toolbar1.Height
End With
End If
If Err.Number <> 0 Then MessageBox.Show("Error Number: " & Err.Number.ToString & ". Error Source: " & Err.Source.ToString & ". This is error in paint 2")
End Sub
The sequence of subroutines that fire when I step through the program after clicking done on frmgraphics is:
First:
Code:
Private Sub ButtonDone_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles ButtonDone.Click
frmBackground.Enabled = True
Me.Close()
End Sub
Code:
Private Sub frmGraphics_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
Call IBACKShow()
End Sub
Code:
Sub IBACKShow()
If IUTL = 5 Then
frmBackground.Enabled = False
Exit Sub
End If
frmBackground.Enabled = True
End Sub
I believe the problem occurs because I have not understood fully the sequence of paint events that are initiated by windows and how vb.net handles them. Any ideas as to where the problem may lie would be greatly appreciated.
Thank you for your time.
Last edited by a moderator: