CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Apr 2003
    Posts
    4

    Question 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.

  2. #2
    Join Date
    Apr 2003
    Posts
    4
    does anyone know how to do this at all, or point me in the right direction?

  3. #3
    Join Date
    Aug 2002
    Location
    Germany, Berlin
    Posts
    60
    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.

  4. #4
    Join Date
    Apr 2003
    Posts
    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.

  5. #5
    Join Date
    Jul 2002
    Location
    .NET 2.0/.NET 3.0/.NET 3.5 VS2005/VS2008
    Posts
    284
    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?

  6. #6
    Join Date
    Jul 2002
    Location
    EU
    Posts
    68
    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?

  7. #7
    Join Date
    Apr 2003
    Posts
    4
    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.

  8. #8
    Join Date
    Sep 2000
    Posts
    109

    Exclamation 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,

  9. #9
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    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

  10. #10
    Join Date
    Sep 2000
    Posts
    109

    Smile

    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,

  11. #11
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    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
  •  





Click Here to Expand Forum to Full Width

Featured