Re: How to word wrap tab title in tab control
- From: "Mick Doherty" <EXCHANGE#WITH@xxxxxxxxxxxxxxxxxxxxxxxxxx[mdaudi100#ntlworld.com]>
- Date: Mon, 18 Jul 2005 13:09:49 +0100
Visual Styles only applies to XP and above. In this case you'll need to
ownerdraw the Tabs.
Here's a basic example for top or bottom aligned tabs with no Image, that
allows you to include the full text at designtime.
(assumes tabControl is named tabControl1).
\\\
private Hashtable multiLineTabs = new Hashtable();
private bool multiLine;
private void Form1_Load(object sender, System.EventArgs e)
{
foreach(TabPage tab in this.tabControl1.TabPages)
{
int newLineIndex = tab.Text.IndexOf(@"\n");
if (newLineIndex !=- 1)
{
if (!multiLine)
{
multiLine = true;
tabControl1.Padding = new Point(6, tabControl1.Font.Height);
}
multiLineTabs.Add(tab,tab.Text.Remove(0,newLineIndex + 2));
tab.Text = tab.Text.Substring(0,newLineIndex);
}
}
}
private void tabControl1_DrawItem(object sender,
System.Windows.Forms.DrawItemEventArgs e)
{
TabControl tabControl = (TabControl)sender;
TabPage currentTab = tabControl.TabPages[e.Index];
Graphics g = e.Graphics;
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
string tabText = currentTab.Text;
RectangleF tabRect = (RectangleF)e.Bounds;
RectangleF textRect = tabRect;
if (e.Index == tabControl.SelectedIndex)
{
tabRect.Inflate(1,1);
}
g.Clip = new Region(tabRect);
g.Clear(Control.DefaultBackColor);
g.ResetClip();
if (multiLine)
{
if (multiLineTabs.Contains(currentTab))
{
tabText += "\n" + (string)multiLineTabs[currentTab];
}
}
g.DrawString(tabText,e.Font,SystemBrushes.ControlText,textRect,sf);
}
///
--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
.
- References:
- How to word wrap tab title in tab control
- From: ColinC
- Re: How to word wrap tab title in tab control
- From: Mick Doherty
- Re: How to word wrap tab title in tab control
- From: ColinC
- How to word wrap tab title in tab control
- Prev by Date: Active are for controls
- Next by Date: How to resume thread?
- Previous by thread: Re: How to word wrap tab title in tab control
- Next by thread: how to change the value of Request.ServerVariables["HTTP_REFERER"] on the ser ver? if not possible is there some way to change it by sending back javascript to the client and having the client automaticaly do something to change the value of Request.Server
- Index(es):
Relevant Pages
|