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
11 namespace TabControlTest
12 {
13 public partial class Form1 : Form
14 {
15 public Form1()
16 {
17 InitializeComponent();
18 }
19
20 const int CLOSE_SIZE = 15;
21 //tabPage標簽圖片
22 Bitmap image = new Bitmap("E:\1\2.jpg");
23 //繪制“X”號即關閉按鈕
24 private void MainTabControl_DrawItem(object sender, DrawItemEventArgs e)
25 {
26
27 try
28 {
29 Rectangle myTabRect = this.MainTabControl.GetTabRect(e.Index);
30
31 //先添加TabPage屬性
32 e.Graphics.DrawString(this.MainTabControl.TabPages[e.Index].Text
33 , this.Font, SystemBrushes.ControlText, myTabRect.X + 2, myTabRect.Y + 2);
34
35 //再畫一個矩形框
36 using (Pen p =