Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Circle.IntersectsWith

Circle.IntersectsWith

Scheduled Pinned Locked Moved C#
csharpwinformsgraphicshelptutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gnjunge
    wrote on last edited by
    #1

    Hi, On my C# winforms project I have received some fairly large rounded buttons from the graphics department. Since they are large I cannot cheat and take their rectangular outline as "hotspot" area for mouse enter/leave (to change cursor to hand, and back) and click. So with other words the code Rectangle.IntersectsWith(Control.MousePosition) doesn't do it for me. I need some code that is Circle.IntersectsWith(Control.MousePosition). Did anybody encounter this problem, and has a simple solution for it? Or can give me tips how to handle this problem? Tnx.

    L R 2 Replies Last reply
    0
    • G gnjunge

      Hi, On my C# winforms project I have received some fairly large rounded buttons from the graphics department. Since they are large I cannot cheat and take their rectangular outline as "hotspot" area for mouse enter/leave (to change cursor to hand, and back) and click. So with other words the code Rectangle.IntersectsWith(Control.MousePosition) doesn't do it for me. I need some code that is Circle.IntersectsWith(Control.MousePosition). Did anybody encounter this problem, and has a simple solution for it? Or can give me tips how to handle this problem? Tnx.

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Look at Region and/or GraphicsPath :) xacc.ide-0.1.1 released! :) Download and screenshots

      G 1 Reply Last reply
      0
      • L leppie

        Look at Region and/or GraphicsPath :) xacc.ide-0.1.1 released! :) Download and screenshots

        G Offline
        G Offline
        gnjunge
        wrote on last edited by
        #3

        Tnx, I created a GraphicsPath, added an ellipse. From that I created a new Region, and on mouseover I check if the mouseposition is Visible (Region.IsVisible)

        1 Reply Last reply
        0
        • G gnjunge

          Hi, On my C# winforms project I have received some fairly large rounded buttons from the graphics department. Since they are large I cannot cheat and take their rectangular outline as "hotspot" area for mouse enter/leave (to change cursor to hand, and back) and click. So with other words the code Rectangle.IntersectsWith(Control.MousePosition) doesn't do it for me. I need some code that is Circle.IntersectsWith(Control.MousePosition). Did anybody encounter this problem, and has a simple solution for it? Or can give me tips how to handle this problem? Tnx.

          R Offline
          R Offline
          Robert Rohde
          wrote on last edited by
          #4

          If its a real circle than Pythagoras could help:

          public bool IsWithin(Button button, int x, int y) {
          //assuming x and y are relative within the button rect
          //which is totally filled by the circle
          int halfButtonSize = button.Width / 2;
          int distFromCenterX = x - halfButtonSize;
          int distFromCenterY = y - halfButtonSize;
          int distFromCenterTotal = Math.Sqrt(distFromCenterX * distFromCenterX
          + distFromCenterY * distFromCenterY);
          if (distFromCenterTotal <= halfButtonSize)
          OnButtonClick(EventArgs.Empty);
          }

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups