Clicking on a Control Array of Shapes
Hello Everyone!
I'm trying to help a friend make Connect 4 in VB6 but I'm running into a problem with handling the event of someone clicking on one of the circles. The goal is that when a person clicks on a circle the Subroutine is called with the index as an argument, but for some reason the code doesn't run.
Below is my code:
Code:
Private Sub Shape1_Click(ByVal Index As Integer)
MsgBox (Index) 'Will be replaced with functioning code upon bugfix
End Sub
Thanks to everyone in advance!
Re: Clicking on a Control Array of Shapes
You cannot click on a shape....place a same-color label on top of it and use the label's click event. (Of course, the label will be a square and won't completely cover the same area as the circle, but this is the easiest and quickest way to do it).
EDIT: You can also use pictureboxes with circular images in them. Many ways to do this, but there is no direct clicking on a shape control (That "I" know of)
Re: Clicking on a Control Array of Shapes
Quote:
Originally Posted by
ahjohnston25
... but for some reason the code doesn't run.
Below is my code:
Code:
Private Sub Shape1_Click(ByVal Index As Integer)
MsgBox (Index) 'Will be replaced with functioning code upon bugfix
End Sub
You can make it run by adding the following code to your Form:
Code:
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim Shp As Control
For Each Shp In Controls
If TypeOf Shp Is Shape Then
If Shp.Left <= X And X <= (Shp.Left + Shp.Width) Then
If Shp.Top <= Y And Y <= (Shp.Top + Shp.Height) Then
Shape1_Click Shp.Index
Exit Sub
End If
End If
End If
Next
End Sub
BTW, I think Sam's idea is less hassle! :thumb:
Re: Clicking on a Control Array of Shapes
AH
Just to confirm Sam's EDIT .. he was correct.
As more of a geek-speak way of explaining, the Shape control does not support any Events,
and Click is an Event.
Spoo