-
Form gets redrawn
Or atleast, that's what I think.
I have an application upgraded from VB6 to VB.Net. I am using the following code to call the method to open an xml file and draw the graph based on the file contents.
Public Sub mnuFileOpen_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mnuFileOpen.Click
FileOpen_Renamed()
End Sub
But just after executing the end sub, whatever i have drwn gets erased. And when I lok through the debugger, th step goes nowhere.
I am new to VS.Net. Any help would be appreciated.
Thanks,
Smitha.
-
Put your drawing code in the OnPaint event .
-
It didn't help. Thanks for the suggestion though.
-
Then your problem is not with form redraw ? Show some code to help others figure out what's your problem ! :confused:
-
Hello Pirate,
Thanks for taking your time to answer.
When I put the code to call tge method draw the graph in On Paint event, it goes into an infinite loop, it just draws and redraws the same thing again and again.
Could you please tell me what I am doing wrong?
Thanks
Smitha.
-
Problem not with events
There are few new things in .net in terms of GDI. I hope that your code is not using the line, circle objects which are obsolete in VB.net.
In previous threads you have tried changing the events but I think the problem lies in the function where you draw.
Can you show us the code so that we get a better picture? It is essential as the Graphics objects have gone through major changes in vb.net.
-
Another way to pertain your drawings is to save them in a image . Post some code ...
-
Here is the sample code:
Public Const cEDITGRID As Short = 500
If mnuModeEdit.Checked Then DrawGrid(cEDITGRID, cEDITGRID)
endif
Public Sub DrawGrid(ByRef CellH As Short, ByRef CellW As Short, Optional ByRef XOffset As Short = 0, Optional ByRef YOffset As Short = 0)
Dim Index As Integer
Dim OldColor, OldWidth As Integer
Dim yVal As Integer
Dim XVal As Integer
Dim yVal1 As Integer
Dim XVal1 As Integer
'Draw Grid
With mForm
OldColor = System.Drawing.ColorTranslator.ToOle(.ForeColor)
OldWidth = grayPen.Width
g = mForm.CreateGraphics()
grayPen.Width = 1 : .ForeColor = System.Drawing.ColorTranslator.FromOle(&H8000000C)
For Index = XOffset To VB6.PixelsToTwipsX(.Width) Step CellW
yVal = VB6.PixelsToTwipsY(.Height) - 500
XVal = VB6.TwipsToPixelsX(Index)
g.DrawLine(grayPen, XVal, YOffset, XVal, yVal)
Next
For Index = YOffset To VB6.PixelsToTwipsY(.Height) - CellH Step CellH
yVal1 = VB6.PixelsToTwipsX(.Width)
XVal1 = VB6.TwipsToPixelsY(Index)
g.DrawLine(grayPen, 0, XVal1, yVal1, XVal1)
Next
grayPen.Width = OldWidth : .ForeColor = System.Drawing.ColorTranslator.FromOle(OldColor)
End With
End Sub