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
            }
  • 相关阅读:
    数字音频接口
    xargs命令详解,xargs与管道的区别
    RmNet,CDC-ECM ,NDIS,RNDIS区别
    Python并发编程之多进程(理论)
    网络编程
    type和object
    《流畅的python》读书笔记,第一章:python数据模型
    用 做出进度条
    如何使用特殊方法
    ValueError: too many values to unpack (expected 2)
  • 原文地址:https://www.cnblogs.com/JohnnyBao/p/4402871.html
Copyright © 2011-2022 走看看