打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
ToolStripSplitButton Checked 效果

ToolStripSplitButton 系统默认没有Checked效果,MS又说他们没时间改。只能自己处理一下了。

重载OnPaint(PaintEventArgs e)

if(Checked)

Rectangle rect = ButtonBounds;

using (Brush br = new LinearGradientBrush(rect, ProfessionalColors.ButtonCheckedGradientBegin,ProfessionalColors.ButtonCheckedGradientEnd,LinearGradientMode.Vertical))

{e.Graphics.FillRectangle(br, rect);}

rect.Inflate(-1, -1);

e.Graphics.DrawRectangle(new System.Drawing.Pen(ProfessionalColors.ButtonSelectedHighlightBorder), rect);

base.OnPaint(e);


ToolStripSplitButton 的button 部分没有Checked propery,下列方法简单的解决这个问题:在button 的checkd 时,额外绘制一些图形,效果如下:

using System.Drawing;

using System.Drawing.Drawing2D;

using System.Windows.Forms;

using System.Windows.Forms.VisualStyles;

namespace  SplitButton

{

     public class ToolStripSplitButtonEx : ToolStripSplitButton

     {

         private bool @checked = false;

         public ToolStripSplitButtonEx()

         {

         }

         public bool Checked

         {

            get { return @checked; }

            set

             {

                 @checked = value;

                 Invalidate();

             }

         }

         protected override void OnPaint(PaintEventArgs e)

         {

             if (@checked)

             {

                     Rectangle rect = ButtonBounds;

                     using (Brush br = new LinearGradientBrush(rect,ProfessionalColors.ButtonCheckedGradientBegin,ProfessionalColors.ButtonCheckedGradientEnd,LinearGradientMode.Vertical))

                     {

                         e.Graphics.FillRectangle(br, rect);

                     }

                     rect.Inflate(-1, -1);

                     e.Graphics.DrawRectangle(Pens.Black, rect);

             }

             base.OnPaint(e);

         }

     }

 }

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Winform重绘单选、多选控件
C#GDI+编程基础(一:Graphics画布类)
MFC背景图像加载
VC++单文档导入背景图片
Layered Window(分层窗体,透明窗体)
c# 绘制图形
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服