Click to See Complete Forum and Search --> : Enabling Buttons on a Parent form from a child form
DangerMouse9
April 17th, 2003, 02:20 PM
I'm not sure how to do this in C#, but I have several buttons on my Parent Form that I want to enable when the user has successfully logged in. How can I enable buttons on the parent form from the child form (ie. I know in VB it's formName.item.property, but since VB is quite different than C# that line of thinking doesn't work for me.
One other question I have that pertains to that is how can I make a child form have an application.modal property?
your help is appreciated.
Thanks.
DangerMouse9
April 21st, 2003, 01:11 PM
does anyone know how to do this at all, or point me in the right direction? :(
Holiday
April 21st, 2003, 03:51 PM
Probably, you don't need to access the parent form from your child form. U can use a successful login to come back to your parent and enabling then the btn by value i.e.
child.doModal();
parent.btn.enable=child.btnOK;
for modal() property, try
using System.Windows.Forms; //for new forms
or derive the child from your parent
child : parent
If that doesn't meet your requirements please give more details.
DangerMouse9
April 22nd, 2003, 09:28 PM
ok, I am having a lot of problems setting up any of the child forms as modal.
Also, I would like to be able to re-enable certain properties on my parent form from the child form.
For instance, the user must log-in successfully before they are allowed to pull up a form that allows them to manipulate a file.
Once the form to manipulate the files is menu item that calls the form is disabled so there are no more than once instance of said form.
I want to be able to re-enable that menu item when the user closes the file manipulation form.
Those are the two things I am having problems with. I appreciate the help.
Thanks.
WillemM
April 23rd, 2003, 06:06 AM
Like this: Form1 calls Form2.
Form2 frm = new Form2();
frm.ShowDialog();
---------------------
From Form2 you do:
Form1 prt = (Form1)this.Parent;
prt.btn1.Enabled = true;
------------
This should be about it.
petru66
April 25th, 2003, 01:16 PM
Originally posted by WillemM
From Form2 you do:
Form1 prt = (Form1)this.Parent;
prt.btn1.Enabled = true;
This should be about it.
Hmmm... isn't here a tiny threading issue? I mean, well, as far as I know, any changes on a form must be done in the same thread that generated the form. Do enabling/disabling a control fall into this category of changes, that require Invoke?
DangerMouse9
April 29th, 2003, 02:32 PM
Ok, I was able to figure out how to do it, and will post it here for the rest of you. Finally I can take some asprine and stop beating my head against a wall. :)
on Form1:
void functionOnForm1()
{
itemname.property = XXXXX;
}
on Form2:
((Form1)this.ParentForm).functionOnForm1();
I went with this route and had a function on Form1 change the properties on that form.
Thanks all that helped.
gee
April 29th, 2003, 03:17 PM
Hi there,
I just try to do the same way you show. I got a problem :
((Form1)this.ParentForm).functionOnForm1() is null. Could you give me a clue?
Tnx,
pareshgh
April 29th, 2003, 04:39 PM
yeap, the parent form is not set so it will be null only. if you are working in MDI application then the parent form will make more sense.
-Paresh
gee
April 29th, 2003, 04:55 PM
Hey pareshgh,
thx for replay. what if I don't want to use MDI form? Is there the way to do this? Or the only way is to use MDI approach?
Regards,:cool:
pareshgh
April 29th, 2003, 05:00 PM
in non-MDI case you will pass reference of the current form in the second form
and thus you access that in second form.
Paresh
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.