ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Image Controls (https://www.excelbanter.com/excel-programming/333396-image-controls.html)

Sandy[_6_]

Image Controls
 
I am attempting to study VBA in excel. Mostly from a text book. In the book
at the end of each chapter "challenges" are set. I'm doing fine with the
exception of the following....

"Draw a simple image of a smiley face using 'ms paint' then load the image
into an Image Control placed on a worksheet in Excel. (No problem so far.)
Using the MouseDown() event procedure of the Image Control write a procedure
that displays a message to the user every time the user clicks on the
image.(Now the hard bit!) The message should tell the user if they clicked
on the eyes, nose, mouth or face and which button they used. (Where do the
buttons come into the image??) The message can be displayed with a Message
Box, or in a Label Control or on the spreadsheet."

That's it, - any ideas would be most welcome.



K Dales[_2_]

Image Controls
 
Private Sub Image1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer,
ByVal X As Single, ByVal Y As Single)

From the Image's MouseDown Event Help File entry:

Button Required. An integer value that identifies which mouse button caused
the event.
Shift Required. The state of SHIFT, CTRL, and ALT.
X, Y Required. The horizontal or vertical position, in points, from the left
or top edge of the form, Frame, or Page.

Using these you should be able to get all the info you need. Any point
(eyes, mouth, etc) on your picture will be at a particular x,y point and you
may need to experiment to find the right values for these (try MsgBox X & ":"
& Y while you test this - so any time you click you will see what x and y
are; by clicking in the area around the eyes, nose, etc. you should be able
to come up with ranges of values that correspond to these points). Will
leave the rest for you since the whole point is to learn, right?

"Sandy" wrote:

I am attempting to study VBA in excel. Mostly from a text book. In the book
at the end of each chapter "challenges" are set. I'm doing fine with the
exception of the following....

"Draw a simple image of a smiley face using 'ms paint' then load the image
into an Image Control placed on a worksheet in Excel. (No problem so far.)
Using the MouseDown() event procedure of the Image Control write a procedure
that displays a message to the user every time the user clicks on the
image.(Now the hard bit!) The message should tell the user if they clicked
on the eyes, nose, mouth or face and which button they used. (Where do the
buttons come into the image??) The message can be displayed with a Message
Box, or in a Label Control or on the spreadsheet."

That's it, - any ideas would be most welcome.




Sandy[_6_]

Image Controls
 
Works brilliantly

Thanks

"K Dales" wrote in message
...
Private Sub Image1_MouseDown(ByVal Button As Integer, ByVal Shift As
Integer,
ByVal X As Single, ByVal Y As Single)

From the Image's MouseDown Event Help File entry:

Button Required. An integer value that identifies which mouse button
caused
the event.
Shift Required. The state of SHIFT, CTRL, and ALT.
X, Y Required. The horizontal or vertical position, in points, from the
left
or top edge of the form, Frame, or Page.

Using these you should be able to get all the info you need. Any point
(eyes, mouth, etc) on your picture will be at a particular x,y point and
you
may need to experiment to find the right values for these (try MsgBox X &
":"
& Y while you test this - so any time you click you will see what x and y
are; by clicking in the area around the eyes, nose, etc. you should be
able
to come up with ranges of values that correspond to these points). Will
leave the rest for you since the whole point is to learn, right?

"Sandy" wrote:

I am attempting to study VBA in excel. Mostly from a text book. In the
book
at the end of each chapter "challenges" are set. I'm doing fine with the
exception of the following....

"Draw a simple image of a smiley face using 'ms paint' then load the
image
into an Image Control placed on a worksheet in Excel. (No problem so
far.)
Using the MouseDown() event procedure of the Image Control write a
procedure
that displays a message to the user every time the user clicks on the
image.(Now the hard bit!) The message should tell the user if they
clicked
on the eyes, nose, mouth or face and which button they used. (Where do
the
buttons come into the image??) The message can be displayed with a
Message
Box, or in a Label Control or on the spreadsheet."

That's it, - any ideas would be most welcome.







All times are GMT +1. The time now is 12:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com