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. MDI parent child interaction

MDI parent child interaction

Scheduled Pinned Locked Moved C#
helpannouncementlearning
5 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.
  • T Offline
    T Offline
    tim_gunning
    wrote on last edited by
    #1

    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 have private void OnMouseMove(object sender, MouseEventArgs e) { coordsPanel f = new coordsPanel(); f.updateCoords(e); } and in coordsPanel.cs I have public 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

    M 1 Reply Last reply
    0
    • T tim_gunning

      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 have private void OnMouseMove(object sender, MouseEventArgs e) { coordsPanel f = new coordsPanel(); f.updateCoords(e); } and in coordsPanel.cs I have public 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

      M Offline
      M Offline
      mikone
      wrote on last edited by
      #2

      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

      T 1 Reply Last reply
      0
      • M mikone

        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

        T Offline
        T Offline
        tim_gunning
        wrote on last edited by
        #3

        hi mik i tried that but no joy im afraid..... am playing with EventHandlers now to see if that help t

        M 1 Reply Last reply
        0
        • T tim_gunning

          hi mik i tried that but no joy im afraid..... am playing with EventHandlers now to see if that help t

          M Offline
          M Offline
          mikone
          wrote on last edited by
          #4

          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.

          T 1 Reply Last reply
          0
          • M mikone

            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.

            T Offline
            T Offline
            tim_gunning
            wrote on last edited by
            #5

            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

            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