Results 1 to 8 of 8

Thread: Form gets redrawn

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    9

    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.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Put your drawing code in the OnPaint event .

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    9
    It didn't help. Thanks for the suggestion though.

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Then your problem is not with form redraw ? Show some code to help others figure out what's your problem !

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    9
    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.

  6. #6
    Junior Member
    Join Date
    Jun 2004
    Posts
    29

    Wink 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.
    Give me a place to stand and I will move the Earth

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Another way to pertain your drawings is to save them in a image . Post some code ...

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    9
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width