none
DrawLine Doesn't Work First Time RRS feed

  • Question

  • I'm having a problem drawing a simple line on a label if the label visible is initially set to false. If I click the button a second time the line appears. I've tried refreshing the label which didn't help. My guess is that the label is still being made visible when the DrawLine is called. I note if I insert a delay by calling a messagebox after lblChart.Visible = True the line appears when the messagebox is closed.

    Is there a way to get the DrawLine to work without having to click the button twice.

     

    Thanks

     

    Code Block

    Private Sub Button1_Click(ByVal sender As System.Object, _

    ByVal e As System.EventArgs) Handles Button1.Click

     

    Dim myPen As Pen = New Pen(Color.Red)

    Dim formGraphics As Graphics

     

    lblChart.Visible = True

     

    formGraphics = Me.lblChart.CreateGraphics()

    formGraphics.DrawLine(myPen, 10, 10, 200, 200)

     

    End Sub

     

     

     

    Tuesday, October 23, 2007 11:12 PM

Answers

  • Code Block

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    lblChart.Visible = True

    lblChart.Refresh()

    Dim myPen As Pen = New Pen(Color.Red)

    Dim formGraphics As Graphics

     

     

    formGraphics = Me.lblChart.CreateGraphics()

    formGraphics.DrawLine(myPen, 10, 10, 200, 200)

    End Sub

     

     

    After you set it as visible, refresh it.  That should work...it worked for me. Wink

     

    Thanks,

    paoloTheCool

    Wednesday, October 24, 2007 12:08 AM

All replies

  • Code Block

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    lblChart.Visible = True

    lblChart.Refresh()

    Dim myPen As Pen = New Pen(Color.Red)

    Dim formGraphics As Graphics

     

     

    formGraphics = Me.lblChart.CreateGraphics()

    formGraphics.DrawLine(myPen, 10, 10, 200, 200)

    End Sub

     

     

    After you set it as visible, refresh it.  That should work...it worked for me. Wink

     

    Thanks,

    paoloTheCool

    Wednesday, October 24, 2007 12:08 AM
  • Thanks Paolo. I guess I wasn't putting the lblChart.Refresh() in the right place.

     

    Wednesday, October 24, 2007 1:56 AM
  • Your welcome Smile

     

    paoloTheCool

     

    Wednesday, October 24, 2007 2:19 AM