Child Window Interaction

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

My MDI (Parentform) form can have 2 two type of forms (Datagridform and
graphicform). When users create a new form, they have to pick either child
form. When those child forms are created and user move the mouse over on one
of the child form, I want the rest of the childs form know about it. For
example, when the cursor is moving on a graphicform, I want the rest of the
graphic forms know the location of the mouse. The forms that are
datagridform should ignore this kind of information.

How can that be achieved?

Thanks,
Anthony
 
ATT said:
My MDI (Parentform) form can have 2 two type of forms (Datagridform and
graphicform). When users create a new form, they have to pick either child
form. When those child forms are created and user move the mouse over on one
of the child form, I want the rest of the childs form know about it. For
example, when the cursor is moving on a graphicform, I want the rest of the
graphic forms know the location of the mouse. The forms that are
datagridform should ignore this kind of information.

How can that be achieved?

One way that comes to mind would be to have a static event in each child
form's class. In the constructor for each child form, that instance
would subscribe itself to the event. The child form would also handle
the appropriate events (I think you'd probably want the
Control.MouseEnter and Control.MouseLeave events, but I'm guessing since
you're asking the question you already have an idea of how you actually
want to detect the mouse movements), and upon detecting the mouse moving
over itself, raise the static event so that all of the other instances
of the same class know about it.

Pete
 
Pete,

Thanks for the suggestion. I have an override on OnMouseMove on the child
form. This is how I capture there is some movement on my application. You
mention "raise the static event so that all of the other instances of the
same class know about it." The question is how? I am new in Window
programming. Can you provide more detail on how to raise the event?

Thanks,
Anthony.
 
ATT said:
Thanks for the suggestion. I have an override on OnMouseMove on the child
form. This is how I capture there is some movement on my application. You
mention "raise the static event so that all of the other instances of the
same class know about it." The question is how? I am new in Window
programming. Can you provide more detail on how to raise the event?

You may find this helpful:

http://msdn2.microsoft.com/en-us/library/aa645739(VS.71).aspx
 
Peter,

Thanks again to the pointer. I read more on events and delegates and come
with this code:

namespace test
{
public class mouseEvent : EventArgs
{
public string message = null;
public EventArgs e = null;
}
public class eventHandling
{
public event EventHandler Changed;

public void onChanged(mouseEvent e)
{
if (Changed != null)
Changed(this, e);
}
}
}

namespace test
{
public partial class Form1 : Form
{
private eventHandling eventhandle = new eventHandling();
public Form1()
{
InitializeComponent();
eventhandle.Changed += new EventHandler(MouseMoveHandler);
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
string message = "x: " + e.X.ToString() + " y: " + e.Y.ToString();
mouseEvent parm = new mouseEvent();
parm.e = e;
parm.message = message;
eventhandle.onChanged(parm);
}
private void MouseMoveHandler(object sender, EventArgs e)
{
mouseEvent parm = (mouseEvent)e;
label1.Text = parm.message;
}
}
}

The second section of the code is on the child form. When doing the test, I
can see my text updated with the current position of the cursor. But it does
not update the text on other child forms. The text is updated only for its
own window. How can I make all the child form see the same message?

Thanks in advance,
Anthony.
 
ATT said:
[...]
The second section of the code is on the child form. When doing the test, I
can see my text updated with the current position of the cursor. But it does
not update the text on other child forms. The text is updated only for its
own window. How can I make all the child form see the same message?

As I mentioned in my suggestion, the event needs to be static, so that
all form instances are using the same event.

Personally, I would just put the event in the form class itself. But if
you want it in a separate class, you can. Doing it that way, you should
either make the separate class a static class (since there's not really
anything in the class that you need to have per-instance), or you should
at least make static the form class's field that stores the reference to
your event handling class.

If you put the event in your form class instead, then you just need to
make the event field itself static.

Pete
 
Peter,

I got it to work. Thank you for your help.

Anthony.

Peter Duniho said:
ATT said:
[...]
The second section of the code is on the child form. When doing the test, I
can see my text updated with the current position of the cursor. But it does
not update the text on other child forms. The text is updated only for its
own window. How can I make all the child form see the same message?

As I mentioned in my suggestion, the event needs to be static, so that
all form instances are using the same event.

Personally, I would just put the event in the form class itself. But if
you want it in a separate class, you can. Doing it that way, you should
either make the separate class a static class (since there's not really
anything in the class that you need to have per-instance), or you should
at least make static the form class's field that stores the reference to
your event handling class.

If you put the event in your form class instead, then you just need to
make the event field itself static.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top