Re-draw the Tabpage tag of TabControl, add image and close button

Source: Internet
Author: User

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 tag Image
22 Bitmap image = new Bitmap ("E: \ 1 \ 2.jpg ");
23 // draw the "X" sign to close the button
24 private void MainTabControl_DrawItem (object sender, DrawItemEventArgs e)
25 {
26
27 try
28 {
29 Rectangle myTabRect = this. MainTabControl. GetTabRect (e. Index );
30
31 // Add the TabPage attribute first
32 e. Graphics. DrawString (this. MainTabControl. TabPages [e. Index]. Text
33, this. Font, SystemBrushes. ControlText, myTabRect. X + 2, myTabRect. Y + 2 );
34
35 // draw another rectangle
36 using (Pen p =

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.