Hi,
When set the DrawMode property to OwnerDrawFixed, the tabControl raises the DrawItem event whenever it needs to paint one of its tabs. Then you can handle the DrawItem event of TabControl that renders the text from left to right.
The following page tells about that:
How to: Display Side-Aligned Tabs with TabControl
http://msdn.microsoft.com/en-us/library/ms404305.aspx
The following is the code in C++:
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
{
tabControl1->Alignment = TabAlignment::Left;
tabControl1->SizeMode = TabSizeMode::Fixed;
tabControl1->ItemSize.Height = 100;
tabControl1->ItemSize.Width = 20;
tabControl1->DrawMode = TabDrawMode::OwnerDrawFixed;
}
private: System::Void tabControl1_DrawItem(System::Object^ sender, System::Windows::Forms::DrawItemEventArgs^ e)
{
Graphics^ g = e->Graphics;
Brush^ _TextBrush;
TabPage^ _TabPage = tabControl1->TabPages[e->Index];
Rectangle _TabBounds = tabControl1->GetTabRect(e->Index);
if (e->State == DrawItemState::Selected)
{
_TextBrush = gcnew SolidBrush(Color::Red);
g->FillRectangle(Brushes::Gray, e->Bounds);
}
else
{
_TextBrush = gcnew SolidBrush(e->ForeColor);
e->DrawBackground();
}
System::Drawing::Font^ _TabFont = gcnew System::Drawing::Font("Arial", 10, FontStyle::Bold, GraphicsUnit::Pixel);
StringFormat^ _StringFlags = gcnew StringFormat();
_StringFlags->Alignment = StringAlignment::Center;
_StringFlags->LineAlignment = StringAlignment::Center;
g->DrawString(_TabPage->Text, _TabFont, _TextBrush, _TabBounds, _StringFlags);
}
Best regards,
Ling Wang
Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.