Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DoubleBufferedTabControl : TabControl
- {
- public DoubleBufferedTabControl() : base()
- {
- this.DoubleBuffered = true;
- this.SetStyle
- (
- ControlStyles.UserPaint |
- ControlStyles.AllPaintingInWmPaint |
- ControlStyles.ResizeRedraw |
- ControlStyles.OptimizedDoubleBuffer |
- ControlStyles.SupportsTransparentBackColor,
- false
- );
- }
- }
- private void Navigation_PageContent_DrawItem(object sender, DrawItemEventArgs e)
- {
- //Structure.
- Graphics g = e.Graphics;
- TabControl t = (TabControl)sender;
- TabPage CurrentPage = t.TabPages[e.Index];
- //Get the current tab
- Rectangle CurrentTabRect = t.GetTabRect(e.Index);
- //Get the last tab.
- Rectangle LastTab = t.GetTabRect(t.TabPages.Count - 1);
- //Main background rectangle.
- Rectangle BackgroundRect = new Rectangle(LastTab.Width, t.Bounds.Y - 4, t.Width - (LastTab.Width), t.Height);
- //Tab background rectangle.
- Rectangle TabBackgroundRect = new Rectangle(0, LastTab.Y + LastTab.Height, LastTab.Width, t.Bounds.Height - (LastTab.Y + LastTab.Height));
- //Set anitialiasing for the text.
- e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
- //String format for the text.
- StringFormat StringFormat = new StringFormat();
- StringFormat.Alignment = StringAlignment.Center;
- StringFormat.LineAlignment = StringAlignment.Center;
- //Fill the background.
- g.FillRectangle(Brushes.LightGray, BackgroundRect);
- g.FillRectangle(Brushes.Bisque, TabBackgroundRect);
- //Draw the selected tab.
- if(e.State == DrawItemState.Selected)
- {
- g.FillRectangle(Brushes.White, e.Bounds);
- Rectangle SelectedTabOutline = new Rectangle(e.Bounds.X + 2, e.Bounds.Y + 2, e.Bounds.Width, e.Bounds.Height - 4);
- g.DrawRectangle(new Pen(Brushes.LightGray, 4f), SelectedTabOutline);
- g.DrawString(CurrentPage.Text, new Font("Arial", 12f, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.FromArgb(70, 70, 70)), CurrentTabRect, StringFormat);
- }
- else
- {
- g.FillRectangle(new SolidBrush(Color.FromArgb(230, 230, 230)), e.Bounds);
- g.DrawString(CurrentPage.Text, new Font("Arial", 12f, FontStyle.Regular, GraphicsUnit.Point), Brushes.Gray, CurrentTabRect, StringFormat);
- }
- }
- protected override CreateParams CreateParams
- {
- get
- {
- CreateParams cp = base.CreateParams;
- cp.ExStyle |= 0x02000000;
- return cp;
- }
- }
- protected override void OnPaintBackground( PaintEventArgs pevent )
- {
- //do not call base - I don't want the background re-painted!
- }
Add Comment
Please, Sign In to add comment