Results 1 to 4 of 4

Thread: Clicking on a Control Array of Shapes

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    1

    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!

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    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)
    Last edited by SamOscarBrown; May 24th, 2013 at 10:39 AM.

  3. #3
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Clicking on a Control Array of Shapes

    Quote Originally Posted by ahjohnston25 View Post
    ... 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!
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  4. #4
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    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

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