Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi all,

 

At some months ago I made this question, but I still have not understand well.

The dought is about passing values, data between diferent forms in c#.

I'm developing an application in a MDI environment, and sometimes i need to pass some values from one forms to others, for example: I have the main form (parent) and for each child form i open, i make visible an item in the menubar. this item alows the user to navigate between openned forms.When i close the child form, i want to set the item (corresponding to this child form) in the parent form as uncheked and invisible.

 

I searched in some sites and the common way I found its to create a delegate and public function or event and with these we could pass information from one site to other, but all the examples seamed to me not very clare, and i still not able to to do what i need.

Does anyone has an true example to show me or can paste and comment a piece of code here , for me to try understand better this?

 

Any help will be very welcome,

 

Best regards,

 

Teixeira

Posted

You just need to remember that everything in C# is a pointer. What I usually do to speed things up and keep things simple is feed in the parent form into the child's constructor.

 

here's what the child's constructor might look like

frmParent _parent;

frmChild(frmParent parent)
{
  _parent = parent;
}

 

Here's what a call to the child would then look like:

frmChild child = new frmChild(this);
child.ShowDialog();

From here, you can reference _parent and set things as needed. To do this, I typically create properties with both a get/set instead of giving public access directly to the parent's form controls -- since you will want to sanitize the incoming information most of the time.

 

The other things I do a lot of the time is setup an event handler, like you mentioned.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...