Results 1 to 4 of 4

Thread: Picture Box

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2003
    Posts
    28

    Picture Box

    I have a picture box with the following event procedure

    VB Code:
    1. 'This routine is trigerred when the user click on the picture box,
    2. 'it notes the coordinates of the click
    3. Private Sub picSample_MouseDown(intButton As Integer, intShift As Integer, sngX As Single, sngY As Single)
    4.     'Add the coordinates to the list box in (x,y) format
    5.      lstPositions.AddItem "(" & sngX & "," & sngY & ")"
    6.      'Take those coordinates (where user clicked) and place an 'X'
    7.      picSample.CurrentX = sngX
    8.      picSample.CurrentY = sngY
    9.      picSample.Print "X"
    10. End Sub

    Then the user can remove an entry from the listbox and then remove the X....how can I remove the X?

    VB Code:
    1. 'Removes a selected item from the list box
    2. Private Sub cmdDelete_Click()
    3.     Const colGrey = &H8000000F
    4.     For i = 0 To (lstPositions.ListCount - 1)
    5.         If (lstPositions.Selected(i) = True) Then
    6.             strMid1 = Mid(lstPositions.List(i), 2, (Len(lstPositions.List(i)) - 2))
    7.             strSplit1 = Split(strMid1, ",")
    8.             picSample.CurrentX = strSplit1(0)
    9.             picSample.CurrentY = strSplit1(1)
    10.             picSample.ForeColor = colGrey
    11.             picSample.Print "X"
    12.             lstPositions.RemoveItem lstPositions.ListIndex
    13.             picSample.ForeColor = vbBlack
    14.         End If
    15.     Next i
    16. End Sub

    As you can see I have found a cheap way to do it, but this marks the spot where the X was if a picture exists in the picture box

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Two things.

    1. You need to reverse count a ListBox to 'Remove' an item (or Items), like:
    VB Code:
    1. Private Sub cmdDelete_Click()
    2.     Const colGrey = &H8000000F
    3.     [b]Dim i As Long
    4.     Dim strMid1 As String
    5.     Dim strSplit1() As String[/b]
    6.    
    7.     [b]For i = lstPositions.ListCount - 1 To 0 Step -1[/b] '*** Change
    8.         If lstPositions.Selected(i) = True Then
    9.             strMid1 = Mid$(lstPositions.List(i), 2, (Len(lstPositions.List(i)) - 2))
    10.             strSplit1 = Split(strMid1, ",")
    11.             picSample.CurrentX = strSplit1(0)
    12.             picSample.CurrentY = strSplit1(1)
    13.             picSample.ForeColor = colGrey
    14.             picSample.Print "X"
    15.             [b]lstPositions.RemoveItem (i)[/b] '*** Change
    16.             picSample.ForeColor = vbBlack
    17.         End If
    18.     Next i
    19. End Sub



    2. To remove the (greyed) 'X' you may need to BitBlt the PicBox, do a 'search' and see what you come up with using keyword BitBlt



    Bruce.

  3. #3
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Actually BitBlt may be of no benifit.... Someone else may have a good idea tho

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Sep 2003
    Posts
    28
    yeah I took out the loop and changed the condition, since the list is no longer multiselect

    VB Code:
    1. 'Removes a selected item from the list box
    2. Private Sub cmdDelete_Click()
    3.         'Check to see if an item in the list box has been selected to remove
    4.         If (lstPositions.SelCount = 1) Then
    5.             'Remove the entry from the list box
    6.             lstPositions.RemoveItem (lstPositions.ListIndex)
    7.             'Refresh the image current in the picture box
    8.             picSample.Picture = LoadPicture(cdbFile.FileName)
    9.             'Replace all the remaining X marks from the list box by parsing
    10.             'the list box entries and then printing an X at that location
    11.             For i = 0 To lstPositions.ListCount - 1
    12.                 strMid1 = Mid(lstPositions.List(i), 2, (Len(lstPositions.List(i))) - 2)
    13.                 strSplit1 = Split(strMid1, ",")
    14.                 picSample.CurrentX = strSplit1(0)
    15.                 picSample.CurrentY = strSplit1(1)
    16.                 picSample.Print "X"
    17.             Next i
    18.         End If
    19. End Sub

    But I also have a problem, when I draw a line from one X to the other, the line is not drawn in the center of the X, any ideas?

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