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. Windows Forms
  4. Detect if ANY control is clicked inside a form, regardless of the container

Detect if ANY control is clicked inside a form, regardless of the container

Scheduled Pinned Locked Moved Windows Forms
dockerquestion
8 Posts 6 Posters 5 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.
  • D Offline
    D Offline
    Dennis Bork
    wrote on last edited by
    #1

    Hey all, is there a way to detect if ANY control is clicked inside a form? The MouseUp, -Down and so on events can only be set for the form itself, but as far as I have tested i out not for any controls that reside inside it - true? Is there another way? Cheers, Dennis

    L A J S 5 Replies Last reply
    0
    • D Dennis Bork

      Hey all, is there a way to detect if ANY control is clicked inside a form? The MouseUp, -Down and so on events can only be set for the form itself, but as far as I have tested i out not for any controls that reside inside it - true? Is there another way? Cheers, Dennis

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Please don't crosspost; pick a forum and stick with it. Most of us read multiple forums, and it scatters the answers over various threads. Original thread is here[^].

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]

      P 1 Reply Last reply
      0
      • L Lost User

        Please don't crosspost; pick a forum and stick with it. Most of us read multiple forums, and it scatters the answers over various threads. Original thread is here[^].

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        I feel sorry for this poster. He was told to post here, and he's only done what he was told.

        *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

        "Mind bleach! Send me mind bleach!" - Nagy Vilmos

        CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

        L 1 Reply Last reply
        0
        • P Pete OHanlon

          I feel sorry for this poster. He was told to post here, and he's only done what he was told.

          *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

          "Mind bleach! Send me mind bleach!" - Nagy Vilmos

          CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Yup, I spoke too soon again.

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]

          1 Reply Last reply
          0
          • D Dennis Bork

            Hey all, is there a way to detect if ANY control is clicked inside a form? The MouseUp, -Down and so on events can only be set for the form itself, but as far as I have tested i out not for any controls that reside inside it - true? Is there another way? Cheers, Dennis

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Dennis Bork wrote:

            The MouseUp, -Down and so on events can only be set for the form itself, but as far as I have tested i out not for any controls that reside inside it - true? Is there another way?

            False, anything that inherits from Control[^]. See Richards'[^] answer for a recursive method that loops all controls, and hook 'em up to a single event-handler. The 'sender' argument would tell you what control was clicked.

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]

            1 Reply Last reply
            0
            • D Dennis Bork

              Hey all, is there a way to detect if ANY control is clicked inside a form? The MouseUp, -Down and so on events can only be set for the form itself, but as far as I have tested i out not for any controls that reside inside it - true? Is there another way? Cheers, Dennis

              A Offline
              A Offline
              April Fans
              wrote on last edited by
              #6

              Hello Dennis Bork, With regards to your question, http://stackoverflow.com/questions/986529/how-to-detect-if-the-mouse-is-inside-the-whole-form-and-child-controls-in-c Hope this helps! Best of Luck! With Kind Regards,

              April Comm100 - Leading Live Chat Software Provider

              1 Reply Last reply
              0
              • D Dennis Bork

                Hey all, is there a way to detect if ANY control is clicked inside a form? The MouseUp, -Down and so on events can only be set for the form itself, but as far as I have tested i out not for any controls that reside inside it - true? Is there another way? Cheers, Dennis

                J Offline
                J Offline
                jenitshah
                wrote on last edited by
                #7

                try this logic... On Form MouseClick Event { if typeof control (at current mouse pointer) not equal to panel, and groupbox and... Then { detected that non container contol is clicked } else { detected that container contol is clicked }

                1 Reply Last reply
                0
                • D Dennis Bork

                  Hey all, is there a way to detect if ANY control is clicked inside a form? The MouseUp, -Down and so on events can only be set for the form itself, but as far as I have tested i out not for any controls that reside inside it - true? Is there another way? Cheers, Dennis

                  S Offline
                  S Offline
                  Simon Bridge
                  wrote on last edited by
                  #8

                  Hi, One other (slightly heavy handed) possibility is to override the Windows Procedure in your form. You can then intercept all the windows messages it receives, and filter down to the mouse events. eg:

                  public partial class Form1 : Form
                  {
                      public Form1()
                      {
                          InitializeComponent();
                      }
                  
                      protected override void WndProc(ref Message m)
                      {
                          base.WndProc(ref m);
                      }
                  }
                  

                  You can get an enum containing all the windows message constants here: [^]

                  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