Locked Select Region in a picturebox

  • 12 Juni 2012 14:04
     
     

    Visual Basic.NET 2010, Professional Edition

    I am trying to select several regions region from plotted data.  The plotted data is either calculated or collected as experimental data.  It is presented in a picture box using a color code.  That is, each pixel of the picture at point (x,y) is represented by a color, which indicates its value z.  Once this data is represented in the picture box, I want to select a region by placing the mouse at the upper left part of the picture to be selected, drag to the lower right of the region to be selected, lift up the mouse button, resulting in the region being selected.  As the mouse is dragged, I would like the selected region to be updated on the screen so the user can see the region being selected, releasing the mouse button when the selected region is correct.  I was able to do this in VB6, but am having trouble in the present version of VB.

    The old VB6 code:

    Private Sub pctIntensity_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

      SelectX1 = X

      SelectY1 = Y

      pctIntensity.Picture = pctIntensity.Image

      flagSelectBox = True

    End Sub

    Private Sub pctIntensity_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

      If Not flagSelectBox Then Exit Sub

      SelectX2 = X

      SelectY2 = Y

      pctIntensity.Cls

      pctIntensity.Line (SelectX1, SelectY1)-(SelectX2, SelectY2), vbWhite, B

    End Sub

    Private Sub pctIntensity_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

      Dim xend As Single, yend As Single

      xend = XInc * CLng(X / XInc)

      yend = Yinc * CLng(Y / Yinc)

      flagSelectBox = False

      Call SetupScanParameters

    End Sub

    In VB6, the present image of pctIntensity is placed into the Picture property, so as I move the mouse, it clears the pctIntensity, leaving the image, and then draws a white enclosure around the selected region.  When the mouse button is lifted, the region is selected, and the subroutine SetupScanParameters sets the selected region.

    Unfortunately, these commands are not the same in VB.NET.  How do I do this in VB.NET?

Semua Balasan

  • 12 Juni 2012 14:42
     
     Jawab

    I'm not sure how the drawing is done exactly. The way I'd do it is:

    • Assign one bitmap to the picturebox Image property.
    • Write one method that updates that image taking all parameters into account that influence the result.
    • Call the method whenever any of these parameters changes.

    Armin