Application.Title dynamic update via SelectedIndexChanged

Answered Closed
0
0

Greetings all ,

I couldn’t get this event  TabControl . SelectedIndexChanged ]  to fire until I extended it to a custom method:

tabMain.SelectedIndexChanged += new EventHandler(ActiveTabIndexChange);

Then and ONLY Then would the event fire and I could address  my need…..to dynamically update the browser’s

title,    to reflect the currently active “form” ( TabPage of TabControl.TabPageCollection  )  in  Application.Title

private void ActiveTabIndexChange(object sender, EventArgs e)
{
TabControl mainTabCtrl = (TabControl)sender;
TabControl.TabPageCollection tabPages = mainTabCtrl.TabPages;
var iSelectedTabIndex = mainTabCtrl.SelectedIndex;
TabPage currentTabPage = tabPages[iSelectedTabIndex];
Application.Title = currentTabPage.Text;
}

Is there a cleaner way to accomplish this ?

please  & Thank you

 

 

 

  • You must to post comments
Best Answer
0
0

Hello,

I’m not exactly sure what you mean by “I couldn’t get this event  TabControl .  [ SelectedIndexChanged ]  to fire until I extended it to a custom method”

All events have to be attached to an event handler, otherwise, they wouldn’t be fired.

What you did to update the Browser Tab Title is correct, but it can be done in fewer lines of code like:

 

private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
TabControl tabControl = (TabControl)sender;

Application.Title = tabControl.TabPages[tabControl.SelectedIndex].Text;
}

HTH,
Alaa

  • You must to post comments
Showing 1 result