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