zoukankan      html  css  js  c++  java
  • Winform 中tabcontrol 美化

    需要对tabcontrol按照美工出的图进行美化

    对tabpage页进行标题设置,首先对整个tabcontrol的DrawMode设置为OwnerDrawFixed,由于需要对标题宽度有要求,设置sizemode为fixed,可以对itemsize调整,设置标题的宽和高,然后进行写事件就能实现

     private void tb_DrawItem(object sender, DrawItemEventArgs e)
            {
                StringFormat sf = new StringFormat();
    
                #region 头背景
                sf.LineAlignment = StringAlignment.Center;
                sf.Alignment = StringAlignment.Center;
                Rectangle rec = tb.ClientRectangle;
                //获取背景图片,我的背景图片在项目资源文件中。
                Image backImage = Properties.Resources.pop_tab1_2;
                e.Graphics.DrawImage(backImage, 0, 2, tb.Width, tb.ItemSize.Height + 2);
                #endregion
                #region  设置选择的标签的背景
                if (e.Index == tb.SelectedIndex)
                    e.Graphics.DrawImage(Properties.Resources.pop_tab1_1, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);
                else
                    e.Graphics.DrawImage(Properties.Resources.pop_tab1_2, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);
                e.Graphics.DrawString(((TabControl)sender).TabPages[e.Index].Text,
                System.Windows.Forms.SystemInformation.MenuFont, new SolidBrush(Color.Black), e.Bounds, sf);
                #endregion
                #region 重写标签名
                ColorConverter colorConverter = new ColorConverter();
                Color cwhite = (Color)colorConverter.ConvertFromString("#2178ba");
                SolidBrush white = new SolidBrush(cwhite);
                Rectangle rect0 = tb.GetTabRect(0);
                StringFormat stringFormat = new StringFormat();
                stringFormat.Alignment = StringAlignment.Center;
                stringFormat.LineAlignment = StringAlignment.Center;
           e.Graphics.DrawString("申请单号", new Font("微软雅黑", 12), white, rect0, stringFormat);
               #endregion
            }
  • 相关阅读:
    zookeeper使用场景
    zookeeper安装配置
    hadoop 远程调试
    deep learning笔记
    Sentiment Analysis(1)-Dependency Tree-based Sentiment Classification using CRFs with Hidden Variables
    PRML阅读笔记 introduction
    Python 学习笔记(2)
    python nltk 学习笔记(5) Learning to Classify Text
    python nltk 学习笔记(4) Writing Structured Programs
    python nltk 学习笔记(3) processing raw text
  • 原文地址:https://www.cnblogs.com/JohnnyBao/p/4402871.html
Copyright © 2011-2022 走看看