iTz_Mercury

C# Tab Control [BOTTOM ALIGNTMENT]

Jun 2nd, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace WindowsFormsApplication1
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.  
  19.         private void tabControl1_DrawItem_1(object sender, DrawItemEventArgs e)
  20.         {
  21.             Graphics g = e.Graphics;
  22.             Brush _textBrush;
  23.  
  24.             // Get the item from the collection.
  25.             TabPage _tabPage = tabControl1.TabPages[e.Index];
  26.  
  27.             // Get the real bounds for the tab rectangle.
  28.             Rectangle _tabBounds = tabControl1.GetTabRect(e.Index);
  29.  
  30.             if (e.State == DrawItemState.Selected)
  31.             {
  32.  
  33.                 // Draw a different background color, and don't paint a focus rectangle.
  34.                 _textBrush = new SolidBrush(Color.Black);
  35.                 g.FillRectangle(Brushes.White, e.Bounds);
  36.             }
  37.             else
  38.             {
  39.                 _textBrush = new System.Drawing.SolidBrush(e.ForeColor);
  40.                 e.DrawBackground();
  41.             }
  42.  
  43.             // Use our own font.
  44.             Font _tabFont = new Font("Arial", (float)10.0, FontStyle.Bold, GraphicsUnit.Pixel);
  45.  
  46.             // Draw string. Center the text.
  47.             StringFormat _stringFlags = new StringFormat();
  48.             _stringFlags.Alignment = StringAlignment.Center;
  49.             _stringFlags.LineAlignment = StringAlignment.Center;
  50.             g.DrawString(_tabPage.Text, _tabFont, _textBrush, _tabBounds, new StringFormat(_stringFlags));
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment