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
  1. Home
  2. General Programming
  3. C#
  4. Click outside of form detection

Click outside of form detection

Scheduled Pinned Locked Moved C#
question
4 Posts 4 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.
  • C Offline
    C Offline
    cdengler
    wrote on last edited by
    #1

    Ok, I'm sure there's an easy answer to this... I just can't figure this out? DUH.. I have a main application (form) that brings up a different form. What I want to do, is to detect ANY click while this new form is up. If the click is OUTSIDE the bounds of this form, I want to perform some action (such as closing the form). Any ideas?

    J M C 3 Replies Last reply
    0
    • C cdengler

      Ok, I'm sure there's an easy answer to this... I just can't figure this out? DUH.. I have a main application (form) that brings up a different form. What I want to do, is to detect ANY click while this new form is up. If the click is OUTSIDE the bounds of this form, I want to perform some action (such as closing the form). Any ideas?

      J Offline
      J Offline
      J Dunlap
      wrote on last edited by
      #2

      If you're just wanting to monitor mouse messages for a short period of time (such as for a popup/menu), you can set the form's Capture property to true. This will redirect all mouse messages to your window. After the first click outside of your window, the mouse capture will be released and you won't get any more mouse messages from outside your form. Other windows, including child windows on your form, will not recieve any mouse messages while your form has the mouse capture. If you need child windows to recieve mouse messages, release the capture when the mouse moves within your form's bounds. Note that it is bad practice to capture the mouse for more than just a brief period/operation, as the mouse pointer is a shared system resource.

      "A people that values its privileges above its principles soon loses both."
      -- Dwight D. Eisenhower

      1 Reply Last reply
      0
      • C cdengler

        Ok, I'm sure there's an easy answer to this... I just can't figure this out? DUH.. I have a main application (form) that brings up a different form. What I want to do, is to detect ANY click while this new form is up. If the click is OUTSIDE the bounds of this form, I want to perform some action (such as closing the form). Any ideas?

        M Offline
        M Offline
        mav northwind
        wrote on last edited by
        #3

        Well, a maybe simpler way could be to add an event handler for the Leave or Deactivate event. The moment the user clicks outside your form it's losing focus and this event can be caught and handled. But you have to remember that when you close the form yourself then these events are generated as well IIRC. And that switching the window by using Alt-TAB for example also triggers this event, not just mouse clicks. Regards, mav

        1 Reply Last reply
        0
        • C cdengler

          Ok, I'm sure there's an easy answer to this... I just can't figure this out? DUH.. I have a main application (form) that brings up a different form. What I want to do, is to detect ANY click while this new form is up. If the click is OUTSIDE the bounds of this form, I want to perform some action (such as closing the form). Any ideas?

          C Offline
          C Offline
          cjengler
          wrote on last edited by
          #4

          At least you have a decent user name :)

          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