|
-
Sep 10th, 2003, 09:36 PM
#1
Thread Starter
Junior Member
Picture Box
I have a picture box with the following event procedure
VB Code:
'This routine is trigerred when the user click on the picture box,
'it notes the coordinates of the click
Private Sub picSample_MouseDown(intButton As Integer, intShift As Integer, sngX As Single, sngY As Single)
'Add the coordinates to the list box in (x,y) format
lstPositions.AddItem "(" & sngX & "," & sngY & ")"
'Take those coordinates (where user clicked) and place an 'X'
picSample.CurrentX = sngX
picSample.CurrentY = sngY
picSample.Print "X"
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:
'Removes a selected item from the list box
Private Sub cmdDelete_Click()
Const colGrey = &H8000000F
For i = 0 To (lstPositions.ListCount - 1)
If (lstPositions.Selected(i) = True) Then
strMid1 = Mid(lstPositions.List(i), 2, (Len(lstPositions.List(i)) - 2))
strSplit1 = Split(strMid1, ",")
picSample.CurrentX = strSplit1(0)
picSample.CurrentY = strSplit1(1)
picSample.ForeColor = colGrey
picSample.Print "X"
lstPositions.RemoveItem lstPositions.ListIndex
picSample.ForeColor = vbBlack
End If
Next i
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
-
Sep 10th, 2003, 10:04 PM
#2
Two things.
1. You need to reverse count a ListBox to 'Remove' an item (or Items), like:
VB Code:
Private Sub cmdDelete_Click()
Const colGrey = &H8000000F
[b]Dim i As Long
Dim strMid1 As String
Dim strSplit1() As String[/b]
[b]For i = lstPositions.ListCount - 1 To 0 Step -1[/b] '*** Change
If lstPositions.Selected(i) = True Then
strMid1 = Mid$(lstPositions.List(i), 2, (Len(lstPositions.List(i)) - 2))
strSplit1 = Split(strMid1, ",")
picSample.CurrentX = strSplit1(0)
picSample.CurrentY = strSplit1(1)
picSample.ForeColor = colGrey
picSample.Print "X"
[b]lstPositions.RemoveItem (i)[/b] '*** Change
picSample.ForeColor = vbBlack
End If
Next i
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.
-
Sep 10th, 2003, 10:13 PM
#3
Actually BitBlt may be of no benifit.... Someone else may have a good idea tho
-
Sep 10th, 2003, 10:32 PM
#4
Thread Starter
Junior Member
yeah I took out the loop and changed the condition, since the list is no longer multiselect
VB Code:
'Removes a selected item from the list box
Private Sub cmdDelete_Click()
'Check to see if an item in the list box has been selected to remove
If (lstPositions.SelCount = 1) Then
'Remove the entry from the list box
lstPositions.RemoveItem (lstPositions.ListIndex)
'Refresh the image current in the picture box
picSample.Picture = LoadPicture(cdbFile.FileName)
'Replace all the remaining X marks from the list box by parsing
'the list box entries and then printing an X at that location
For i = 0 To lstPositions.ListCount - 1
strMid1 = Mid(lstPositions.List(i), 2, (Len(lstPositions.List(i))) - 2)
strSplit1 = Split(strMid1, ",")
picSample.CurrentX = strSplit1(0)
picSample.CurrentY = strSplit1(1)
picSample.Print "X"
Next i
End If
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|