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