0

Let's say I have a Form that has a label and a tabControl. The basic way to use this form is

 Form myForm3b = new Form();
 if (myForm3b.ShowDialog() != DialogResult.OK)
{
}

So the first line builds the form and the second one shows it and waits for the form to be closed. Now, let's say the tabControl has three tabs and I want to:

  • Make the third and not the first tab to be selected by default OR
  • Make the default tab to appear dependant on some previous calculation OR
  • Make the content of the label to reflect some previous string value

I suppose I can modify the constructor to pass the string value (I have not tried it) but I tried to somehow pass some parameter to the constructos so that the form select its shown default tab but it did not work (it always shows the first tab by default)

So what I am asking is how to correctly customize the appearance of a form before showing it?

KansaiRobot
  • 7,564
  • 11
  • 71
  • 150
  • 1
    You can change the default `tab` in `tabControl` like `tabControl1.SelectedTab = tabPage3;` in `Form_Load`. – SH7 Feb 20 '19 at 06:24
  • Thanks! Apparently I was using a different thing to select tabs and it didn't work. Now it seems to be working. – KansaiRobot Feb 20 '19 at 06:28

1 Answers1

2

One of many ways you can do this

public partial class Form
{

    ...
    public void MyAwesomeMethodThatDoesEverything(int magicNumber)
    {
        // Your hearts desires here
    }
}

Usage

Form myForm3b = new Form();
myForm3b.MyAwesomeMethodThatDoesEverything(int magicNumber);
if (myForm3b.ShowDialog() != DialogResult.OK)
{ ... }
TheGeneral
  • 79,002
  • 9
  • 103
  • 141