Probably simple but I'm having trouble

  • Thread starter Thread starter Jim H
  • Start date Start date
J

Jim H

I'm new to gui programming. I'm just doing some testing with forms. I've
dropped a com control on a form. When a user clicks and holds the mouse
down on the control I'd like to drag the form around with the mouse. How
would I do this? Even is it were a simple control like a label or panel,
how would I do this?

I guess it comes down to 2 questions:
1. How do I get mouse movement messages if the control does not offer these
messages? Can I get them from some base control. It's ok if I'm taking the
controls ability to process mouse messages away.

2. How do I determine if the mouse button is currently down?


Thanks
jim
 
Hi Jim H,

For you 2nd question, below is the solution:

private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
switch (e.Button)
{
case MouseButtons.Left:
MessageBox.Show("Left Mouse Button Click");
break;
case MouseButtons.Right:
MessageBox.Show("Right Mouse Button Click" );
break;
default:
break;
}
}

Hope it helps. Cheers.
 
Hi Jim H,

For question 1, mouse movement:

private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
textBox1.Text = "X: " + e.X + " Y: " + e.Y;
}

Hope it works. Thanks.
 
Thanks for the response. The problem events do not get kicked off when the
mouse is over the child control. How do I track the mouse when it is over a
third party control?

jim

Chua Wen Ching said:
Hi Jim H,

For question 1, mouse movement:

private void Form1_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)
 
Hi Jim,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to move the form around when
hold the mouse button on one control. If there is any misunderstanding,
please feel free to let me know.

This can be only be done if the third party control can process mouse move
event. If there is not a mouse move event fired by that control, we will
not have a place to write code to do this stuff.

For workaround, we can try to make a derived class of the ActiveX control
and override the OnMouseMove event. In the OnMouseMove event, we can fire
another public event, for example, named "MyMouseMove". Now we can handle
the MyMouseMove to achieve this.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Hi Jim H,

Over a 3rd party control? Do you have the code for it and is it managed?

Anyway i never tried before. Hope there is someone who can help you.

Keep me updated if you can find the solution.

I am here to learn too.
 
Back
Top