Permalink
Cannot retrieve contributors at this time
Fetching contributors…
| using System; | |
| using System.Collections.Generic; | |
| using System.ComponentModel; | |
| using System.Data; | |
| using System.Drawing; | |
| using System.Text; | |
| using System.Windows.Forms; | |
| namespace TestVerticalTabsCS | |
| { | |
| public partial class Form1 : Form | |
| { | |
| //<SNIPPET1> | |
| public Form1() | |
| { | |
| // Remove this call if you do not program using Visual Studio. | |
| InitializeComponent(); | |
| tabControl1.DrawItem += new DrawItemEventHandler(tabControl1_DrawItem); | |
| } | |
| private void tabControl1_DrawItem(Object sender, System.Windows.Forms.DrawItemEventArgs e) | |
| { | |
| Graphics g = e.Graphics; | |
| Brush _textBrush; | |
| // Get the item from the collection. | |
| TabPage _tabPage = tabControl1.TabPages[e.Index]; | |
| // Get the real bounds for the tab rectangle. | |
| Rectangle _tabBounds = tabControl1.GetTabRect(e.Index); | |
| if (e.State == DrawItemState.Selected) | |
| { | |
| // Draw a different background color, and don't paint a focus rectangle. | |
| _textBrush = new SolidBrush(Color.Red); | |
| g.FillRectangle(Brushes.Gray, e.Bounds); | |
| } | |
| else | |
| { | |
| _textBrush = new System.Drawing.SolidBrush(e.ForeColor); | |
| e.DrawBackground(); | |
| } | |
| // Use our own font. | |
| Font _tabFont = new Font("Arial", (float)10.0, FontStyle.Bold, GraphicsUnit.Pixel); | |
| // Draw string. Center the text. | |
| StringFormat _stringFlags = new StringFormat(); | |
| _stringFlags.Alignment = StringAlignment.Center; | |
| _stringFlags.LineAlignment = StringAlignment.Center; | |
| g.DrawString(_tabPage.Text, _tabFont, _textBrush, _tabBounds, new StringFormat(_stringFlags)); | |
| } | |
| //</SNIPPET1> | |
| } | |
| } |