#1
  1. Business Analyst
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2004
    Location
    The 'Ville
    Posts
    1,087
    Rep Power
    22

    Question Detect mouse click in irregular area


    I want to capture a mouse click on a PictureBox and perform one action if it is in area A but a different action if it is in area B. Unfortunately the shape is not a rectangle or circle. It will be more or less a semi-circle. I don't want to actually draw this semi-circle, just be able to tell whether or not the click is in the given area using some kind of coordinate system.

    I know how to capture a mouse click in general, just need help with the specific area part.

    Well, now that I think about it, this is really pretty similar to an old-school image map hyperlink in HTML!

    Any ideas?

    Thanks!
    Last edited by mateoc15; July 18th, 2008 at 10:48 AM.
    Discontent is the first necessity of progress. - Edison
  2. #2
  3. Arcane Scribbler
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2005
    Location
    Indianapolis, IN
    Posts
    1,907
    Rep Power
    585
    Rectangle and RectangleF have bool IntersectsWith() methods.

    Region has several bool IsVisible() overloads, one of which is bool IsVisible( Point ).

    Even GraphicsPath can be used because one of Region's constructors takes a GraphicsPath argument.

    System.Drawing.Region.IsVisible()

    Edit: There may even be better ways of doing hit testing, but I don't know 'em. Yet.
    Joel B Fant
    "An element of conflict in any discussion is a very good thing. Shows everybody's taking part, nobody left out. I like that."

    .NET Must-Haves
    Tools: Reflector
    References: Threading in .NET
  4. #3
  5. Business Analyst
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2004
    Location
    The 'Ville
    Posts
    1,087
    Rep Power
    22
    Any idea how this works in WPF?
    Discontent is the first necessity of progress. - Edison

IMN logo majestic logo threadwatch logo seochat tools logo