Windows Develop Bookmark and Share   
 index > Windows Forms General > Visual C++ 2008 Windows Form TabControl
 

Visual C++ 2008 Windows Form TabControl

Hi there, can someone please tell me how do I make the Tab Control Text Horizontal, because I have changed the TabControl Orientation To left.
Now I want to rotate the tabs text horizontal. Because it looksbad when it is vertical.
Thank you,
Regards.
Trust No one
  • Moved byNancy ShaoMSFTThursday, September 17, 2009 10:04 AMTo get better support (From:Visual C++ General)
  •  
switch13  Tuesday, September 15, 2009 8:50 AM
TabControl does not natively support this.

You'll need to ownerdraw the TabControl in order to achieve this effect.
Mick Doherty
http://dotnetrix.co.uk
Mick Doherty  Thursday, September 17, 2009 5:34 PM

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.
Ling Wang  Tuesday, September 22, 2009 7:55 AM
Ask in the Windows Forms forum. The Windows Forms class library is language-independent.

The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
Visual C++ MVP
Sheng Jiang 蒋晟  Tuesday, September 15, 2009 3:57 PM
Hi Switch13,

I am moving this thread from Base "Visual C++ General" forum to the "Windows Forms General" forum, since the issue is related to Windows Forms. There are moreWindowsFormsexperts in the "Windows Forms General" forum.

Best Regards,
Nancy


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Nancy Shao  Thursday, September 17, 2009 10:04 AM
TabControl does not natively support this.

You'll need to ownerdraw the TabControl in order to achieve this effect.
Mick Doherty
http://dotnetrix.co.uk
Mick Doherty  Thursday, September 17, 2009 5:34 PM
Thanx for all the replies, I'll check it out.
Trust No one
switch13  Monday, September 21, 2009 6:29 AM
Hi Switch13,

I am moving this thread from Base "Visual C++ General" forum to the "Windows Forms General" forum, since the issue is related to Windows Forms. There are moreWindowsFormsexperts in the "Windows Forms General" forum.

Best Regards,
Nancy


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

Hi Nancy, can you please give me a link to this post in the forum. Thanx.
Trust No one
switch13  Monday, September 21, 2009 6:29 AM
Hi Switch,

I have alreadly movedthis threadto the " Windows Forms General "Forum, please check the top of this thread:

Windows Developer Center > Windows Forms Forums > Windows Forms General > Visual C++ 2008 Windows Form TabControl

Best Regards,
Nancy


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Nancy Shao  Monday, September 21, 2009 6:35 AM

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.
Ling Wang  Tuesday, September 22, 2009 7:55 AM

You can use google to search for other answers

Custom Search

More Threads

• VB.NET Form Events V's C# Form Events
• How to access parent form methods from a user control.
• About the forms
• BackgroundWorker hoses message pump
• databinding in diferent forms,with C#
• How to get \n into a listview
• Timer Function problem
• RegAsm error because it is not a valid .NET assembly using VS2005
• Chart,Graph
• 120dpi and vs.net form designer