1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38:
| public class Tab : TabControl {
public Tab () { this.Anchor = AnchorStyles.Top; this.Dock = DockStyle.Top; this.DrawMode = TabDrawMode.OwnerDrawFixed; this.DrawItem += HandleDrawItem; }
private void HandleDrawItem (object sender, DrawItemEventArgs e) { Color color; if (e.Index == this.SelectedIndex) color = Color.White; else color = Color.FromArgb(240,240,240);
using (Brush br = new SolidBrush(color)) { e.Graphics.FillRectangle (br, e.Bounds); SizeF sz = e.Graphics.MeasureString (this.TabPages [e.Index].Text, e.Font); e.Graphics.DrawString (this.TabPages [e.Index].Text, e.Font, Brushes.Black, e.Bounds.Left + (e.Bounds.Width - sz.Width) / 2, e.Bounds.Top + (e.Bounds.Height - sz.Height) / 2 + 1); Rectangle rect = e.Bounds; rect.Offset (0, 1); rect.Inflate (0, -1); e.Graphics.DrawRectangle (Pens.LightGray, rect); e.DrawFocusRectangle(); } }
public void add(string name){ TabPage tp = new TabPage(name); tp.BackColor = Color.White; this.Controls.Add(tp); } } |