MDI parent child interaction
-
hi all i was playing around making a small image viewer app type thing (first foray into windows apps) and have run into a problem geting the child forms (or any off them for that matter) to communicate in a way I want, I'm not sure if its even possible, it should be as it seems to me to be a relatively fundamental use of them. basically I was trying to get the mouse coordinates to update another child form that iwas going to use as a control, so ...the parent form opens the two child forms, one contains a picture anmd the other is just for info (the coords), I can pass the info over if I do a
MessageBox.Show("e.X.ToString());
however when I try to update, say a label it doesnt do anything. I imagine I'm doing something idiotic or missing something very basic, but like I said I'm jst on a learning curve atm ;0 in Form2.cs I haveprivate void OnMouseMove(object sender, MouseEventArgs e) { coordsPanel f = new coordsPanel(); f.updateCoords(e); }
and in coordsPanel.cs I havepublic void updateCoords(MouseEventArgs e) { MessageBox.Show(label1.Text);//popup shows orig value label1.Text ="foo"; MessageBox.Show(e.X.ToString());//popup mouse x coord MessageBox.Show(label1.Text);//popup shows new value(foo) }
the values getting across just not updating. it works fine if its all in one form. The label is declared as :private System.Windows.Forms.Label label1;
I've tried using get/setand nothing seems to work. I DON'T get any errorsand the app works fine so I'm not sure whats happening any pointers appreciated. t -
hi all i was playing around making a small image viewer app type thing (first foray into windows apps) and have run into a problem geting the child forms (or any off them for that matter) to communicate in a way I want, I'm not sure if its even possible, it should be as it seems to me to be a relatively fundamental use of them. basically I was trying to get the mouse coordinates to update another child form that iwas going to use as a control, so ...the parent form opens the two child forms, one contains a picture anmd the other is just for info (the coords), I can pass the info over if I do a
MessageBox.Show("e.X.ToString());
however when I try to update, say a label it doesnt do anything. I imagine I'm doing something idiotic or missing something very basic, but like I said I'm jst on a learning curve atm ;0 in Form2.cs I haveprivate void OnMouseMove(object sender, MouseEventArgs e) { coordsPanel f = new coordsPanel(); f.updateCoords(e); }
and in coordsPanel.cs I havepublic void updateCoords(MouseEventArgs e) { MessageBox.Show(label1.Text);//popup shows orig value label1.Text ="foo"; MessageBox.Show(e.X.ToString());//popup mouse x coord MessageBox.Show(label1.Text);//popup shows new value(foo) }
the values getting across just not updating. it works fine if its all in one form. The label is declared as :private System.Windows.Forms.Label label1;
I've tried using get/setand nothing seems to work. I DON'T get any errorsand the app works fine so I'm not sure whats happening any pointers appreciated. tsometimes (especially when you have a high cpu load) the controls do not invalidate (redraw, whatever ;)) though you change some of their values. In this case, you will have to use "System.Windows.Forms.Application.DoEvents()" - this static method allows you to let your application do all of the stuff in the queue. I guess this won't be a solution for your problem because the interval between popping up a messagebox and clicking its "ok" button is enough time to get its events done... try to add this statement first - if it does not work add a label1.Invalidate() which causes the label to redraw itself and all its child controls. (you also could invalidate the whole form to make sure everythings updated). I guess this will help but i'm not sure at all. Good luck, mik
-
sometimes (especially when you have a high cpu load) the controls do not invalidate (redraw, whatever ;)) though you change some of their values. In this case, you will have to use "System.Windows.Forms.Application.DoEvents()" - this static method allows you to let your application do all of the stuff in the queue. I guess this won't be a solution for your problem because the interval between popping up a messagebox and clicking its "ok" button is enough time to get its events done... try to add this statement first - if it does not work add a label1.Invalidate() which causes the label to redraw itself and all its child controls. (you also could invalidate the whole form to make sure everythings updated). I guess this will help but i'm not sure at all. Good luck, mik
hi mik i tried that but no joy im afraid..... am playing with EventHandlers now to see if that help t
-
hi mik i tried that but no joy im afraid..... am playing with EventHandlers now to see if that help t
-
erm i just noticed you set the labels text to "foo" EVERY time. you should change this to e.X.ToString() to set the labels text to the X position of the mouse.
hi yeah i ended up just trying to get it do anything, its original text value is label1 and should change to foo. the message popups were just to see what was happening