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
            }
  • 相关阅读:
    MyBatis通过JDBC生成的执行语句问题
    request.getParameter()、request.getInputStream()和request.getReader()
    Spring 实现数据库读写分离
    图片分布式存储
    切换城市的功能实现
    一直在前进的路上
    test blog
    SSIS 系列
    微信摇一摇优惠券
    扫描二维码实现一键登录
  • 原文地址:https://www.cnblogs.com/JohnnyBao/p/4402871.html
Copyright © 2011-2022 走看看