Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Parameter Passing on Form Load C#

Options
  • 08-09-2008 7:53pm
    #1
    Registered Users Posts: 1,987 ✭✭✭


    I know very well how to pass parameters but for the life of me i can't figure out how to pass a value from FORM A to FORM B when FORM B loads after a button is pressed on FORM A??

    All help appreciated.

    EDIT: Got it working, using a static class.


Comments

  • Registered Users Posts: 78 ✭✭IsaBrown


    Create a second constructor for FormB that accepts the paramaters.

    public FormB()
    {
    InitializeComponent();
    }


    public FormB(object o) : this()
    {
    paramFromFormA = o
    }



    private void btnOpenFormB_Click(object sender, EventArgs e)
    {
    FromB frmB = new frmB(paramFromFormA);
    frmB.Show();

    }


  • Closed Accounts Posts: 1,444 ✭✭✭Cantab.


    I tend to make just one Form and use lots of UserControls stemming from this one Form

    I then use lots of delegate and event functionality to bounce paramaters around the place.

    Anyone have any comments on this? Is there a cleaner/more efficient way of handling forms where the layout of the visual components needs to change quite a lot?


  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    Unless I'm misunderstanding, you shouldn't need to pass parameters at all. In general if you need to same information available to multiple event handlers/functions you can just put it in class-level variables accessible by anything in the form.

    When you talk about changing the visual components a lot, is the problem that you are removing these from the form but need to keep the values? In that case you should leave them on the form but hide them (you can put the controls in batches onto panel controls to make managing this much easier.)


Advertisement