Looping through VB6 shapes in UserControl

Hi,

I am trying to determine which shape on my user control has been clicked.  I have tried googling but everything seems to come up with VBA which doesnt seem to be easily adaptable to this.

I'm pretty sure I'm close but its either my definition for shp or the collection I'm looping through which is wrong.

Incidentally variable a is just so I can see where I'm at as I step through.

Thanks in advance


Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim shp As Shape
    For Each shp In UserControl.shapes
    a = shp.Name
    If shp.Name = "shpWorkBlock" Then
    If X >= shp.Left And X <= shp.Left + shp.Width And _
        Y >= shp.Top And Y <= shp.Top + shp.Height Then
        MsgBox shp.Index & " has been clicked."
    End If
    End If
    Next shp
End Sub

Open in new window

LVL 1
simonwaitAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
First it looks like UserControl.shapes isn't a valid collection because the "s" in shapes isn't capitalized as it would be by VB6 if it existed.

In your Googling have you come across the lessons surrounding their ShapeLabel control like this one? It seems you have to add and raise events to do what you want.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
simonwaitAuthor Commented:
So I'm wondering if it is wiser to put this shape into a usercontrol by itself and then loop through the usercontrols with a sub in the usercontrol to resize the shape to the usercontrol?
0
Martin LissOlder than dirtCommented:
No I wouldn't think so. Just add a Click event to your shapes.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

simonwaitAuthor Commented:
Im not sure what I have done wrong here but I dont seem to be able to create a click event for the shape.  I then tried to do my idea of putting a shape in a usercontrol and looping through the user controls but I dont seem to be able to do that either.  I cant seem to return basic information such as indexes or change the backcolor property.  Just incase its obvious to someone I will post code here.
0
Martin LissOlder than dirtCommented:
Can you attach a zip file of your project?
0
simonwaitAuthor Commented:
I would but it wont allow some of my file extensions (specifically .ctl) which it found even in the zip

Ive stuck it on Wetransfer at http://we.tl/01x4AZqcJq instead.  

This usually uses a database so has some sql but if you are trying to run it then I have added an auto login button on the login page which will let you in.

The idea is that frmMain has a control ctrlSliders which in turn has multiple instances of CtrlDayBlock.  This in turn has multiple instances of a shape which I have tried 2 different ways.  Firstly as a shape which I then manipulate its size to represent different lengths of time.  Then as I was struggling with looping through those shapes I started looking at manipulating another usercontrol call ctrlBlock.  In many ways I prefer this idea because then I can make changes to just that and not have to replicate it for all of the shapes like I do in the non usercontrol version.

Thanks Martin for you help as ever
0
Martin LissOlder than dirtCommented:
Sorry for the confusion but what I was looking for was the code for the OCXs you wrote which is where the Click event should be added.
0
simonwaitAuthor Commented:
Ah sorry.  That has nadenme realise I've misread the article.  I'm mid connection between Sydney and London so will take a look at some ActiveX examples when I have decent internet
0
Martin LissOlder than dirtCommented:
I'm away from home too until tomorrow evening.
0
simonwaitAuthor Commented:
Great thanks Martin - it took a while but I finally got the concept.  sorry for the confusion I think I couldn't see the wood for the trees.
0
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.