C # TabConTrol control background color

Source: Internet
Author: User

Everyone must have encountered such a problem. When creating a WinForm project, you need to beautify the forms and controls. However, if you use third-party controls, there is no free content, in this case, you need to beautify the built-in visual styles of VS. When beautifying the TabControl control, the problem arises:

 

The BackImage property of the control is not directly set, and the background of the main control cannot be set.

Below I will provide you with a simple method (I am not a professional artist, I do not have much beautification skills, the specific color collocation, I will do it myself! Haha)

Step 1:

Set the DrawMode attribute of the TabControl control (tclDemo is used as an example) to OwnerDrawFixed, which specifies that the title is drawn by the user.

 

Step 2: register the DrawItem event of the TabControl control:

 

Step 3:

 

 

Private void tclDemo_DrawItem (object sender, DrawItemEventArgs e)

 

{

 

// Obtain the work area of the TabControl Master Control

 

Rectangle rec = tclDemo. ClientRectangle;

 

 

 

// Obtain the background image. The background image is in the project resource file.

 

Image backImage = Resources. Maple Leaf;

 

 

 

// Create a StringFormat object for setting the label text Layout

 

StringFormat StrFormat = new StringFormat ();

 

StrFormat. LineAlignment = StringAlignment. Center; // you can specify the vertical Center of the text.

 

StrFormat. Alignment = StringAlignment. Center; // you can specify the horizontal Center of the text.

 

// Tag background fill color, which can be an image

 

SolidBrush bru = new SolidBrush (Color. FromArgb (72,181,250 ));

 

SolidBrush bruFont = new SolidBrush (Color. FromArgb (217, 54, 26); // label font Color

 

Font font = new System. Drawing. Font ("", 12F); // set the label Font style

 

 

 

// Draw the background of the Main Control

 

E. Graphics. DrawImage (backImage, 0, 0, tclDemo. Width, tclDemo. Height );

 

// Draw the label Style

 

For (int I = 0; I <tclDemo. TabPages. Count; I ++)

 

{

 

// Obtain the work area of the label Header

 

Rectangle recChild = tclDemo. GetTabRect (I );

 

// Draw the background color of the label Header

 

E. Graphics. FillRectangle (bru, recChild );

 

// Draw the text of the label Header

 

E. Graphics. DrawString (tclDemo. TabPages [I]. Text, font, bruFont, recChild, StrFormat );

 

}

 

}

 

 

 

 

Let's see the effect!

 

I just want to show you how to set the style and color of the TabControl in a simple way. I will hand it over to the artist !!!

 

From Jia Feng International

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.