|
-
April 17th, 2003, 02:20 PM
#1
Enabling Buttons on a Parent form from a child form
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.
-
April 21st, 2003, 01:11 PM
#2
does anyone know how to do this at all, or point me in the right direction?
-
April 21st, 2003, 03:51 PM
#3
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.
Last edited by Holiday; April 21st, 2003 at 03:56 PM.
-
April 22nd, 2003, 09:28 PM
#4
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.
-
April 23rd, 2003, 06:06 AM
#5
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.
WM.
What about weapons of mass construction?
-
April 25th, 2003, 01:16 PM
#6
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?
-
April 29th, 2003, 02:32 PM
#7
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.
-
April 29th, 2003, 03:17 PM
#8
null?
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,
-
April 29th, 2003, 04:39 PM
#9
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
- Software Architect
-
April 29th, 2003, 04:55 PM
#10
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,
-
April 29th, 2003, 05:00 PM
#11
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
- Software Architect
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|