Plotting Graph

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tigger
    New Member
    • May 2007
    • 37

    #1

    Plotting Graph

    Hi there,
    I seem to face some problems with multiple click event. When i click plotButton, it should plot a cross. For example if user select 250Hz, it will plot a cross at 250Hz. x and y are the pixel values to draw the cross. When the user select a different frequency (eg. 500Hz) and click plotButton again, the cross for the 250Hz will disappear. So how do i make it stay? I think it has got something to do with the plotButton click event.

    [CODE=vbnet]Private Sub Audiogram_Paint (ByVal sender As Object, ByVal e As System.Windows. Forms.PaintEven tArgs) Handles Me.Paint
    If BIEMaskingMachi ne.freqTrackBar .Value = 250 Then
    If BIEMaskingMachi ne.count = -10 Then
    x = 80
    y = 50
    G.DrawLine(Blue pen, (x - 5), (y - 5), (x + 5), (y + 5)) 'drawing 'x'
    G.DrawLine(Blue pen, (x + 5), (y - 5), (x - 5), (y + 5))
    xpoints(0) = G
    End If

    If BIEMaskingMachi ne.freqTrackBar .Value = 500 Then
    If BIEMaskingMachi ne.toneLabel.Te xt = "-10dB" Then
    x = 120
    y = 50
    H.DrawLine(Blue pen, (x - 5), (y - 5), (x + 5), (y + 5)) 'drawing 'x'
    H.DrawLine(Blue pen, (x + 5), (y - 5), (x - 5), (y + 5))
    xplotted500 = H
    End If
    End Sub[/CODE]

    The plotButton is in a different form. This is the code for the plotButton.

    [CODE=vbnet]Private Sub plotButton_Clic k(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles plotButton.Clic k

    'Audiogram.Show Dialog()
    Audiogram.Show( )

    End Sub[/CODE]
    Last edited by Killer42; Jul 23 '07, 06:52 AM. Reason: Added [CODE=vbnet] tags, tidied up indenting.
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Hi tigger.

    I haven't even tried to follow the code yet (assuming I could, since I'm a VB6 developer, not VB.Net). But after tidying up the indenting (sorry, I just like it nice and symmetrical), I have to ask - does the VB.Net compiler really allow you to get away with wildly unbalanced IF...End If structures like that? If so, frankly I'm appalled.

    And I suspect that may be the source of any problems. For instance, the test for freqTrackBar.Va lue = 500 is dependent on the truth of freqTrackBar.Va lue = 250. Unless I've just missed something in between which changes the value, the second test can never be true.

    Comment

    • tigger
      New Member
      • May 2007
      • 37

      #3
      Originally posted by Killer42
      Hi tigger.

      I haven't even tried to follow the code yet (assuming I could, since I'm a VB6 developer, not VB.Net). But after tidying up the indenting (sorry, I just like it nice and symmetrical), I have to ask - does the VB.Net compiler really allow you to get away with wildly unbalanced IF...End If structures like that? If so, frankly I'm appalled.

      And I suspect that may be the source of any problems. For instance, the test for freqTrackBar.Va lue = 500 is dependent on the truth of freqTrackBar.Va lue = 250. Unless I've just missed something in between which changes the value, the second test can never be true.

      Sorry i actually posted only part of the codes. If not, it's quite long.

      [CODE=vbnet]Private Sub Audiogram_Paint (ByVal sender As Object, ByVal e As System.Windows. Forms.PaintEven tArgs) Handles Me.Paint
      If BIEMaskingMachi ne.freqTrackBar .Value = 250 Then
      If BIEMaskingMachi ne.count = -10 Then
      x = 80
      y = 50
      G.DrawLine(Blue pen, (x - 5), (y - 5), (x + 5), (y + 5)) 'drawing 'x'
      G.DrawLine(Blue pen, (x + 5), (y - 5), (x - 5), (y + 5))
      xpoints(0) = G
      End If
      End If

      If BIEMaskingMachi ne.freqTrackBar .Value = 500 Then
      If BIEMaskingMachi ne.toneLabel.Te xt = "-10dB" Then
      x = 120
      y = 50
      H.DrawLine(Blue pen, (x - 5), (y - 5), (x + 5), (y + 5)) 'drawing 'x'
      H.DrawLine(Blue pen, (x + 5), (y - 5), (x - 5), (y + 5))
      xplotted500 = H
      End If
      End If
      End Sub[/CODE]
      Last edited by Killer42; Jul 23 '07, 08:58 AM. Reason: Added [CODE=vbnet] tag

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        I'd be more inclined to suspect the AutoRedraw setting, or whatever the equivalent is in VB.Net.

        Not too sure about VB.Net, but I believe the general way that painting a window (a "window" can be a control such as a picturebox) works is that Windows (or VB) either stores a permanent copy to be thrown back on screen whenever the control needs to be repainted, or it leaves it up to the code in the Paint event procedure to draw it.

        So if Windows is calling this Paint code of yours each time the window (control) needs to be repainted, then I guess you're only going to get whatever your routine says to paint.

        Perhaps you ought to have a look on the web for a tutorial covering how to produce graphics in VB.Net. VB does make things relatively simple, but sometimes it's not quite as simple as it seems.

        Comment

        Working...