Question

Hey I want to open tabpage2 when i'm clicking a button in tabpage1.

How can I do it ? Thanks.

picture :

enter image description here

Was it helpful?

Solution

Your question and your image are two different requests.

For the image, you can use your own event on Form2:

public event EventHandler OpenSecondTabPage;

public Form2() {
  InitializeComponent();
  button1.Click += button1_Click;
}

private void button1_Click(object sender, EventArgs e) {
  OnOpenSecondTabPage();
}

protected void OnOpenSecondTabPage() {
  if (OpenSecondTabPage != null) {
    OpenSecondTabPage(this, EventArgs.Empty);
  }
}

Then in your main form:

protected override void OnShown(EventArgs e) {
  base.OnShown(e);
  Form2 f2 = new Form2();
  f2.OpenSecondTabPage += f2_OpenSecondTabPage;
  f2.ShowDialog(this);
}

void f2_OpenSecondTabPage(object sender, EventArgs e) {
  tabControl1.SelectedTab = tabPage2;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top