Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I changed Alignment property to Left or Right.but the text is in vertical shape.what can I do?
Thank You.
Posted
Updated 10-Feb-12 0:49am
v2
Comments
That's Aragon 10-Feb-12 6:49am    
Edited for grammar.

1 solution

If you wish to have the text aligned horizontally you need to set the DrawMode to OwnerDrawFixed. Then on the DrawItem event, manually draw the control like:

C#
private void tabControl_DrawItem(object sender, DrawItemEventArgs e)
{
    string tabName = tabControl.TabPages[e.Index].Text;
    StringFormat stringFormat = new StringFormat();
    stringFormat.Alignment = StringAlignment.Center;
    stringFormat.LineAlignment = StringAlignment.Center;
    //Find if it is selected, this one will be hightlighted...
    if (e.Index == tabControl.SelectedIndex)
        e.Graphics.FillRectangle(Brushes.LightBlue, e.Bounds);
    e.Graphics.DrawString(tabName, this.Font, Brushes.Black,        tabControl.GetTabRect(e.Index), stringFormat);
}
 
Share this answer
 
Comments
Ramadurai Uthami 18-Feb-12 5:41am    
thank u very much Tony Pazzard

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900