teixeira Posted April 8, 2005 Posted April 8, 2005 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 Quote
Mister E Posted April 8, 2005 Posted April 8, 2005 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. Quote
teixeira Posted April 8, 2005 Author Posted April 8, 2005 I'll try this. God bless you and thanks a lot for the explanantion Teixeira Quote
mskeel Posted April 8, 2005 Posted April 8, 2005 If I understand you correctly, this thread might also be a little helpful. Granted, it is in VB, but it would be trivial to translate it to C#. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.