Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

detecting click

Posted on 2002-03-13
14
Medium Priority
?
271 Views
Last Modified: 2010-05-02
hi is there anyway to detect click within shapes object ?
0
Comment
Question by:prinx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
14 Comments
 
LVL 2

Expert Comment

by:nahumd
ID: 6860201
no
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6860224
Hi prinx,

Try the Form_MouseDown Event:

Example:

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If X >= Shape1.Left And X <= Shape1.Left + Shape1.Width And Y >= Shape1.Top And Y <= Shape1.Top + Shape1.Height Then
        Label1.Caption = "Click inside Shape1"
    Else
        Label1.Caption = "Click outside Shape1"
    End If
End Sub

Hope this help
0
 
LVL 1

Expert Comment

by:tomnich
ID: 6860520
To get ryancys code to work you must set the Form's key preview property to true
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6860555
> To get ryancys code to work you must set the Form's key preview property to true
That is not true, because i use the Mouse Event, it's no about the key pressing..
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6860557
> To get ryancys code to work you must set the Form's key preview property to true
That is not true, because i use the Mouse Event, it's no about the key pressing..
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6860558
sorry for the double posts..
0
 

Author Comment

by:prinx
ID: 6860566
would it work if the shapes an oval ?
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 6860649
Prinx,

   Even though a Shape's appearance may be other than rectangular, EVERY shape is defined within a rectangular space on the form.  EVERY Shape has  Left, Top, Width and Height properties, which define THAT rectangular space.

What ryancys' solution is testing are those properties, so that if the mouse where in fact pointing INSIDE the rectanlge, but OUTSIDE the actual OVAL shap, you would still detect a "hit" on that Shape (consider the upper Left corner of the rectangle - OUTSIDE the oval, but to the right of the extreme left edge of the Oval, and Below the extreem top edge of the rectangle - this would still be seen, by ryancys' code, as being a hit on THAT Shape (resulting with "Click inside Shape1").

If you wanted to be "more accurate", then you would need some very specific computations to determine if the actual X, and Y of the location of the mouse was truly within the REAL boundaries of the actual object, and that might be VERY VERY complicated.

Arthur Wood
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6860653
APIs will do but i don't have resources, sorry..
0
 

Author Comment

by:prinx
ID: 6860696
i was tinking about reading pixels off an image to determine hit area..but i can't find any function to do this..anyone has any idea ?
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6861090
What you are describing can be achieved be reading the help files on User Controls, where they give an example of building a user control that has click-event support.  However, that opens up a whole new realm of learning, especially if you want to allow for transparency of the shapes.
0
 

Expert Comment

by:bill02
ID: 6861209
I would put the shape into a user control then you'll have full control over what happens. you can make it global across all the forms in a project too which helps when you need to make a global change to something. I use them to create my own command buttons that i want more control over and when anything that is going to be repeated in the project several times such as grids and searching functions on that grid. if you need some examples ask ill get you some code.
0
 

Author Comment

by:prinx
ID: 6863830
PtInRegion
The PtInRegion function determines whether the specified point is inside the specified region.

BOOL PtInRegion(
  HRGN hrgn,  // handle to region
  int X,      // x-coordinate of point
  int Y       // y-coordinate of point
);

hi ..can someone pls teach mi how to declare and use this function in visual basic ?
0
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 300 total points
ID: 6863969
A modified example from allapi.net , by still Not working well, just a start points for us maybe:

Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function PtInRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function PtInRegion Lib "gdi32" (ByVal hRgn As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function CreateEllipticRgnIndirect Lib "gdi32" (lpRect As RECT) As Long
Private Declare Function SetPixelV Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long

Private Sub Form_Load()
    Shape1.Shape = 2
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    Dim mRGN As Long, R As RECT
    'Set the graphical mode to persistent
    Me.AutoRedraw = True
    'Set the rectangle's values
    SetRect R, Shape1.Left, Shape1.Top, Shape1.Width, Shape1.Height
    'Create an elliptical region
    mRGN = CreateEllipticRgnIndirect(R)
    If PtInRegion(mRGN, x, y) <> 0 Then
        'SetPixelV Me.hdc, x, y, vbGreen
        Me.Caption = "Selected"
    ElseIf PtInRect(R, x, y) <> 0 Then
        'SetPixelV Me.hdc, x, y, vbRed
        Me.Caption = "Not Selected"
    End If
    'DeleteObject mRGN
End Sub
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question