C# .NET - tab ctrl btn cliked - Asked By Trisha on 10-Feb-12 12:06 AM

i m using tabcontol.. which has 4 tab page.. and i want that when user click on first tab then msg box should be shown first tab clicked and when clicks second then should be shown second tab clikced... i dont know on which event i have to write code.. i want to write code seprately for each tab page when button clicked.
Venkat K replied to Trisha on 10-Feb-12 12:42 AM

Use TagbControl selected changed event instead, or you can also recognize the Enter event when the tab page is clicked in show the message box:
User Control:

namespace TestPropogateTabEvent

{

public partial class UserControlWithTab : UserControl

{

public UserControlWithTab()

{

InitializeComponent();

}

public delegate void TabSelectionEventHandler(object sender, EventArgs e);

public event TabSelectionEventHandler PropogateSelectionChange;

private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
 {

  if (PropogateSelectionChange != null)
  {
   PropogateSelectionChange(sender, e);
  }

}

}

}

Form Class:

namespace TestPropogateTabEvent

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

userControlWithTab1.PropogateSelectionChange += new UserControlWithTab.TabSelectionEventHandler(userControlWithTab1_PropogateSelectionChange);

}

void userControlWithTab1_PropogateSelectionChange(object sender, EventArgs e)

{

MessageBox.Show("Tab In User Control Pressed");

}

}

}
 


Thanks

dipa ahuja replied to Trisha on 10-Feb-12 06:18 AM
Simply implement the SelectedIndexChanged event of tab

private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
  MessageBox.Show("you are at " + tabControl1.SelectedTab.ToString() + " Tab");
 
}