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. MouseMove in a container [modified]

MouseMove in a container [modified]

Scheduled Pinned Locked Moved C#
csharpdocker
6 Posts 2 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.
  • R Offline
    R Offline
    Rafone
    wrote on last edited by
    #1

    Hi; I'm a C#.net newbee trying to convert from VB.net. Don't have the big picture yet I am sure. I am trying to trap the mouse_move event in a panel (container) for the form the code (that works) looks something like this. InitializeComponent(); this.MouseMove += new MouseEventHandler(this.Form1_MouseMove); } //--------------------- Mouse Move ------------------------------ // private void Form1_MouseMove(object sender, MouseEventArgs e) { ...... } If I try to do the same thing in a container it does not work. Can anyone point me in the right direction..... Thanks In Advance Rafone Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ... modified on Friday, September 19, 2008 12:02 AM

    A R 2 Replies Last reply
    0
    • R Rafone

      Hi; I'm a C#.net newbee trying to convert from VB.net. Don't have the big picture yet I am sure. I am trying to trap the mouse_move event in a panel (container) for the form the code (that works) looks something like this. InitializeComponent(); this.MouseMove += new MouseEventHandler(this.Form1_MouseMove); } //--------------------- Mouse Move ------------------------------ // private void Form1_MouseMove(object sender, MouseEventArgs e) { ...... } If I try to do the same thing in a container it does not work. Can anyone point me in the right direction..... Thanks In Advance Rafone Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ... modified on Friday, September 19, 2008 12:02 AM

      A Offline
      A Offline
      Ajay k_Singh
      wrote on last edited by
      #2

      You want to trap mouse move over a panel control, however the event which you have added is for mouse move event of Form and not of panel control. Therefore add event handler for panel control, such as – ----------------------------- private void Form1_Load(object sender, EventArgs e) { this.panel1.MouseMove += new MouseEventHandler(panel1_MouseMove); } void panel1_MouseMove(object sender, MouseEventArgs e) { //Mouse move event of panel } -------------------- -Dave.

      ------------------------------------ http://www.componentone.com ------------------------------------

      R 1 Reply Last reply
      0
      • A Ajay k_Singh

        You want to trap mouse move over a panel control, however the event which you have added is for mouse move event of Form and not of panel control. Therefore add event handler for panel control, such as – ----------------------------- private void Form1_Load(object sender, EventArgs e) { this.panel1.MouseMove += new MouseEventHandler(panel1_MouseMove); } void panel1_MouseMove(object sender, MouseEventArgs e) { //Mouse move event of panel } -------------------- -Dave.

        ------------------------------------ http://www.componentone.com ------------------------------------

        R Offline
        R Offline
        Rafone
        wrote on last edited by
        #3

        thx dave; the code I supplied was the code that works for the form mouse move event. The code that I am trying to get working is... private void Form1_Load(object sender, EventArgs e) { this.MouseMove += new MouseEventHandler(this.panel1_MouseMove); } //--------------------- Mouse Move ------------------------------ private void panel1_MouseMove(object sender, MouseEventArgs e) { Point mousePoint = PointToClient(MousePosition); string msg = string.Format("X:{0}, Y:{1}", mousePoint.X, mousePoint.Y); lblMousePosition.Text = msg; } thx Rafone Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...

        A 1 Reply Last reply
        0
        • R Rafone

          thx dave; the code I supplied was the code that works for the form mouse move event. The code that I am trying to get working is... private void Form1_Load(object sender, EventArgs e) { this.MouseMove += new MouseEventHandler(this.panel1_MouseMove); } //--------------------- Mouse Move ------------------------------ private void panel1_MouseMove(object sender, MouseEventArgs e) { Point mousePoint = PointToClient(MousePosition); string msg = string.Format("X:{0}, Y:{1}", mousePoint.X, mousePoint.Y); lblMousePosition.Text = msg; } thx Rafone Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...

          A Offline
          A Offline
          Ajay k_Singh
          wrote on last edited by
          #4

          I think you are still not getting the point. If this is the code which you have used – private void Form1_Load(object sender, EventArgs e) { this.MouseMove += new MouseEventHandler(this.panel1_MouseMove); } //--------------------- Mouse Move ------------------------------ private void panel1_MouseMove(object sender, MouseEventArgs e) { Point mousePoint = PointToClient(MousePosition); string msg = string.Format("X:{0}, Y:{1}", mousePoint.X, mousePoint.Y); lblMousePosition.Text = msg; } Notice that you are using line – this.MouseMove += new MouseEventHandler(this.panel1_MouseMove); In the above line ‘this’ represents form, and not a panel. So still you are not getting a handler for panel control. Replace the above mentioned line with – panel1.MouseMove += new MouseEventHandler(panel1_MouseMove); Notice that I am using ‘panel1.MouseMove’ and not ‘this.MouseMove’. Here panel1 is name of my panel control, if you have used a different name, you should replace it with the name of your panel control. -Dave.

          ------------------------------------ http://www.componentone.com ------------------------------------

          R 1 Reply Last reply
          0
          • A Ajay k_Singh

            I think you are still not getting the point. If this is the code which you have used – private void Form1_Load(object sender, EventArgs e) { this.MouseMove += new MouseEventHandler(this.panel1_MouseMove); } //--------------------- Mouse Move ------------------------------ private void panel1_MouseMove(object sender, MouseEventArgs e) { Point mousePoint = PointToClient(MousePosition); string msg = string.Format("X:{0}, Y:{1}", mousePoint.X, mousePoint.Y); lblMousePosition.Text = msg; } Notice that you are using line – this.MouseMove += new MouseEventHandler(this.panel1_MouseMove); In the above line ‘this’ represents form, and not a panel. So still you are not getting a handler for panel control. Replace the above mentioned line with – panel1.MouseMove += new MouseEventHandler(panel1_MouseMove); Notice that I am using ‘panel1.MouseMove’ and not ‘this.MouseMove’. Here panel1 is name of my panel control, if you have used a different name, you should replace it with the name of your panel control. -Dave.

            ------------------------------------ http://www.componentone.com ------------------------------------

            R Offline
            R Offline
            Rafone
            wrote on last edited by
            #5

            Thanks again Dave; I think that I have found the problem this event does not fire. Not sure why but the Form Load nevers fires therefore mouse move is not working ... private void Form1_Load(object sender, EventArgs e) but it does not... THX Rafone Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...

            1 Reply Last reply
            0
            • R Rafone

              Hi; I'm a C#.net newbee trying to convert from VB.net. Don't have the big picture yet I am sure. I am trying to trap the mouse_move event in a panel (container) for the form the code (that works) looks something like this. InitializeComponent(); this.MouseMove += new MouseEventHandler(this.Form1_MouseMove); } //--------------------- Mouse Move ------------------------------ // private void Form1_MouseMove(object sender, MouseEventArgs e) { ...... } If I try to do the same thing in a container it does not work. Can anyone point me in the right direction..... Thanks In Advance Rafone Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ... modified on Friday, September 19, 2008 12:02 AM

              R Offline
              R Offline
              Rafone
              wrote on last edited by
              #6

              So in order to get the Form Load event to work I added this to the Designer of the form this.Load += new System.EventHandler(this.Form1_Load); do I need to do this or should VS add this for me when I add the event?? Sorry for these "bone-head" questions but this is the kind-of stuff VB would have added automatically and I'm not sure what has to be added when. THX Rafone

              Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...

              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