yea, makes perfect sense..but i did this yesterday and it worked fine...: using System.Drawing; using System.Windows.Forms;
public class Form1 : Form { private Rectangle tabArea; private System.Windows.Forms.TabControl tabControl1; private RectangleF tabTextArea;
public Form1() { TabControl tabControl1 = new TabControl(); TabPage tabPage1 = new TabPage(); TabPage tabPage2 = new TabPage(); TabPage tabPage3 = new TabPage();
// Allows access to the DrawItem event. tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed;
tabControl1.SizeMode = TabSizeMode.Fixed; tabControl1.Controls.Add(tabPage1); tabControl1.Controls.Add(tabPage2); tabControl1.Controls.Add(tabPage3); tabControl1.ItemSize = new Size(80, 20); tabControl1.Location = new Point(25, 25); tabControl1.Size = new Size(350, 100); TabControl tc = new TabControl(); TabPage tp = new TabPage("hello"); TabPage tp2 = new TabPage("hello2"); TabPage tp3 = new TabPage("hello3"); tc.ItemSize = new Size(80,20); tc.Location = new Point(25,200); tc.Size = new Size(350,100); tp.TabIndex=0; tp2.TabIndex=1; tc.Controls.Add(tp); tc.Controls.Add(tp2); tc.Controls.Add(tp3); tabPage1.TabIndex = 0; tabPage2.TabIndex = 1; tabPage3.TabIndex = 2; ClientSize = new Size(400, 500); Controls.Add(tabControl1); Controls.Add(tc); // Binds the event handler 1DrawOnTab to the DrawItem event // through the DrawItemEventHandler delegate. tabControl1.DrawItem += new DrawItemEventHandler(DrawOnTab); }
// Declares the event handler DrawOnTab which is a method that // draws a string and Rectangle on the tabPage1 tab. private void DrawOnTab(object sender, DrawItemEventArgs e) { e.Graphics.FillRectangle(new SolidBrush(Color.FromName("Control")),e.Bounds); tabArea = e.Bounds; tabTextArea = (RectangleF)e.Bounds; Graphics g = e.Graphics; Pen p = new Pen(Color.Blue); Font font = new Font("Arial", 10.0f); SolidBrush brush = new SolidBrush(Color.Red); tabArea = new Rectangle(e.Bounds.Left+2,e.Bounds.Top+2,e.Bounds.Width-3,e.Bounds.Height-3); Icon x = new Icon(this.Icon,16,16); Rectangle iconRect = new Rectangle(e.Bounds.Left+2,e.Bounds.Top+2,e.Bounds.Height-3,e.Bounds.Width-3); Rectangle textRect = new Rectangle(e.Bounds.Left+10,e.Bounds.Top+2,e.Bounds.Height-3,e.Bounds.Width-22); g.DrawIconUnstretched(x,iconRect); g.DrawString("tab" + e.Index,font,brush,e.Bounds.Left+20,e.Bounds.Top+1); }
private void InitializeComponent() { this.tabControl1 = new System.Windows.Forms.TabControl(); this.SuspendLayout(); // // tabControl1 // this.tabControl1.Location = new System.Drawing.Point(208, 296); this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; this.tabControl1.TabIndex = 0; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(648, 413); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.tabControl1}); this.Name = "Form1"; this.ResumeLayout(false);
}
static void Main() { Application.Run(new Form1()); } }
am i missing something or is this not ownerdrawn?
|