Hello,
I'm writing a program in Visual C# using Visual Studio .NET Professional 2003.
In the main form I have placed a TabControl control with 3 TabPages controls.
I would like that, when a tabpage was selected (with a mouse click or the right arrow key pressed), its title changed color (from black to blue, i.e.) and became bold, to distinguish the selected page from the others (so, when I change page, I also have to switch the previously selected page title from blue to black and from bold to regular).
I thought to organize the code in the way I reported below: my problem is that I don't know how to set the color and the fontstyle of a tabpage title (it would be possible however... or not???).
There is also another strange thing: the program doesn't execute the tabPageOnGotFocus event handler (when I select a tabpage, the statement contained in the event handler
tabPageSelectedTab.Text = "selected";
isn't executed).
I have put a breakpoint too, but the program doesn't stop.
Have I made any errors?
Thank you very much (here is the code)
I'm writing a program in Visual C# using Visual Studio .NET Professional 2003.
In the main form I have placed a TabControl control with 3 TabPages controls.
I would like that, when a tabpage was selected (with a mouse click or the right arrow key pressed), its title changed color (from black to blue, i.e.) and became bold, to distinguish the selected page from the others (so, when I change page, I also have to switch the previously selected page title from blue to black and from bold to regular).
I thought to organize the code in the way I reported below: my problem is that I don't know how to set the color and the fontstyle of a tabpage title (it would be possible however... or not???).
There is also another strange thing: the program doesn't execute the tabPageOnGotFocus event handler (when I select a tabpage, the statement contained in the event handler
tabPageSelectedTab.Text = "selected";
isn't executed).
I have put a breakpoint too, but the program doesn't stop.
Have I made any errors?
Thank you very much (here is the code)
Code:
using System;
using System.Drawing;
using System.Windows.Forms;
class MainForm: Form
{
private TabControl tabControl1;
private TabPage tabPage1, tabPage2, tabPage3;
private TabPage tabPageSelectedTab, tabPageOldSelectedTab;
public static void Main()
{
Application.Run(new MainForm());
}
public MainForm()
{
tabControl1 = new TabControl();
tabPage1 = new TabPage();
tabPage2 = new TabPage();
tabPage3 = new TabPage();
Controls.Add(tabControl1);
tabControl1.Controls.Add(tabPage1);
tabControl1.Controls.Add(tabPage2);
tabControl1.Controls.Add(tabPage3);
tabPage1.Text = "Page 1";
tabPage1.GotFocus += new EventHandler(tabPageOnGotFocus);
tabPage2.Text = "Page 2";
tabPage2.GotFocus += new EventHandler(tabPageOnGotFocus);
tabPage3.Text = "Page 3";
tabPage3.GotFocus += new EventHandler(tabPageOnGotFocus);
tabControl1.SelectedTab = tabPage1;
tabPageSelectedTab = tabPage1;
tabPageOldSelectedTab = tabPage1;
}
void tabPageOnGotFocus(object obj, EventArgs ea)
{
tabPageOldSelectedTab = tabPageSelectedTab;
tabPageSelectedTab = (TabPage)obj;
// code for changing old selected tabpage title from blue
// to black color and from bold to regular fontstyle
// tabPageOldSelectedTab... (???)
// code for changing selected tabpage title from black
// to blue color and from regular to bold fontstyle
// tabPageSelectedTab... (???)
tabPageSelectedTab.Text = "selected";
}
}