zoukankan      html  css  js  c++  java
  • TabControl控件自定义样式

    TabControl控件自定义样式
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    namespace testTabFlash
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                this.tabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;
                this.tabControl1.DrawItem += new DrawItemEventHandler(this.tabControl1_DrawItem);
    
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
    
            }
    
            private void tabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
            {
                Font fntTab;
                Brush bshBack;
                Brush bshFore;
    if (e.Index == this.tabControl1.SelectedIndex)    //当前Tab页的样式
                {
                    fntTab = new Font(e.Font, FontStyle.Bold);
                    bshBack = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, SystemColors.Control, SystemColors.Control, System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);
                    bshFore = Brushes.Black;
                }
                else    //其余Tab页的样式
                {
                    fntTab = e.Font;
                    bshBack = new SolidBrush(Color.Blue);
                    bshFore = new SolidBrush(Color.Black);
                }
                //画样式
                string tabName = this.tabControl1.TabPages[e.Index].Text;
                StringFormat sftTab = new StringFormat();
                e.Graphics.FillRectangle(bshBack, e.Bounds);
                Rectangle recTab = e.Bounds;
                recTab = new Rectangle(recTab.X, recTab.Y + 4, recTab.Width, recTab.Height - 4);
                e.Graphics.DrawString(tabName, fntTab, bshFore, recTab, sftTab);
            }
        }
    }
    
  • 相关阅读:
    每日日报2021.5.14
    每日日报2021.5.13
    每日日报2021.5.12
    每日日报2021.5.11 冲刺第十天
    《梦断代码》读后感3
    每日日报2021.5.10 冲刺第九天
    《梦断代码》读后感2
    每日日报2021 5/23
    每日日报2021 5/22
    每日日报2021 5/21
  • 原文地址:https://www.cnblogs.com/mario/p/1739120.html
Copyright © 2011-2022 走看看