Welcome to WindowsClient.net | My Blog | Sign in | Join

Windows Client Videos

WinForms-FormToForm Using Properties

In this video Pat Tormey shows how to send and receive messages between two or more forms using the technique of creating a custom property for the form.

As forms are also classes you can add a customer Public Property and use it to send and receive (Get/Set) messages. In this example we’ll be using a string but the techniques works for sending an instance of a class which might be more useful in your applications.

This is only one of several ways to handle round tripping messages and is part of a mini-series on just that subject.

Author: Pat Tormey

Comments

em_em said:

Hi, the screencasts you make are really helpful and fun to watch.

I recently ran into a problem that directly relates to this series of yours - "FormToForm". I have an MDI form (learned how use them from one of your video as well) whose status label I want to update based on what happens in one of its child windows. The child window cannot access the parent window's properties and nor does .Show() return a value (based on which I could do what I wanted). I tried (based on suggestions by others) doing AddHandler and RaiseEvent stuff, but that leads to other problems ("Cannot access a disposed object" when trying to load the closed child window a second time). So I was wondering whether you could cover that topic in this series as it does seem like a rather complex thing (and I'm a rather newbie).

Sorry for the long winded post.

Thanks again for your work. It's much appreciated.

- Hassan

# February 20, 2009 9:11 AM

LeeLiam said:

I wasted a couple of hours today downloading a good number of Zune videos from this website. I want to watch them on my Windows Mobile phone so I chose the Zune option. This video seems okay but the majority are TOTALLY out of sync with the audio making them useless. Several seemed to have been hijacked by www.learnvisualstudio.net where the audio and video don't match at all (see Zune-15 Picture Box Control - CS-0.wmv). It took hours to try to get the videos because the site is SO SLOW. Something called live.analytics.com takes FOREVER to load each time you change a page. Please let me know when these things are fixed. Thanks.

# March 7, 2009 10:17 PM

djibril_chimere_diaw said:

Thanks! Jërëjëf!

# March 16, 2009 6:50 AM

Phillip J said:

This is a great video and I was able to put it to immidiate use on another part of the Windows Forms application I am working on...

All except that I am unable to see the properties of form2 from form1.  How do I exppose the properties on form2 to form1?

form1's code sample...

       private void lbWayPoints_SelectedIndexChanged(object sender, EventArgs e)

       {

           // Get the currently selected item in the ListBox.

           string selectedWP = lbWayPoints.Text;

           int selectedWP_ID = lbWayPoints.SelectedIndex;

          // send these parameters over to the WP Details form

          frmWP_Detail.WP_Text.ToString = selectedWP.ToString;

          frmWP_Detail.WP_Index.ToString = selectedWP_ID.ToString;

       }

// On the last 2 lines I get an error that an object referance is missing or...

form2 code sample below......

namespace YachtLog3.Forms

{

   public partial class frmWP_Detail : Form

   {

       // -----------------------------------------------------------------

       // gets the WP Selected Text

       private string varWP_Text;

       public string WP_Text

       {

           get { return varWP_Text; }

           set { varWP_Text = value; }

       }

       // gets the WP selected Index value

       private string varWP_Index;

       public string WP_Index

       {

           get { return varWP_Index; }

           set { varWP_Index = value; }

       }

       // --------------------------------------------------------------

       public frmWP_Detail()

       {

           InitializeComponent();

       }

        private void btnCancel_Click(object sender, EventArgs e)

       {

           this.Close();

       }

# February 12, 2010 7:07 PM

Phillip J said:

Hi,

I have resolved all my isses so far thanks to some great people on the Blogs.

I have watched this video and love the Left Column which is NOT part of the Child area.

What is the best method to add that bar/panel AFTER I have created the application and written a lot of code.

Phill

# February 15, 2010 4:37 PM