zoukankan      html  css  js  c++  java
  • 自定义按钮与颜色和形状

    介绍 这是我第一个c#自定义控件。请下载演示程式并按一下。 特性 用户可以定义: 颜色 边框颜色 正常的颜色 正常颜色B 悬停色一个 悬停色B GradientStyle 水平 垂直 ForwardDiagonal BackwardDiagonal ButtonStyle 矩形 椭圆 SmoothingQuality 没有(脆) 高速 抗锯齿 优质 你可以真正感受到点击与它的扁平风格! OnPaint()中的关键技术 SmoothingModeHide,复制Code

    //
    // set SmoothingMode
    //
    switch (_SmoothingQuality)
    {
        case SmoothingQualities.None:
            e.Graphics.SmoothingMode = SmoothingMode.Default;
            break;
        case SmoothingQualities.HighSpeed:
            e.Graphics.SmoothingMode = SmoothingMode.HighSpeed;
            break;
        case SmoothingQualities.AntiAlias:
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            break;
        case SmoothingQualities.HighQuality:
            e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
            break;
    }

    LinearGradientModeHide,Code

    //
    // mode declaration
    //
    LinearGradientMode mode;

    Hide副本,复制Code

    //
    // set LinearGradientMode
    //
    switch (_GradientStyle)
    {
        case GradientStyles.Horizontal:
            mode = LinearGradientMode.Horizontal;
            break;
        case GradientStyles.Vertical:
            mode = LinearGradientMode.Vertical;
            break;
        case GradientStyles.ForwardDiagonal:
            mode = LinearGradientMode.ForwardDiagonal;
            break;
        case GradientStyles.BackwardDiagonal:
            mode = LinearGradientMode.BackwardDiagonal;
            break;
        default:
            mode = LinearGradientMode.Vertical;
            break;
    }

    LinearGradientBrushHide,Code

    //
    // brush declaration
    //
    LinearGradientBrush brush;

    Hide副本,收缩,复制Code

    switch (_State)
    {
        case _States.Normal:
            brush = new LinearGradientBrush(newRect, 
                    _NormalColorA, _NormalColorB, mode);
            switch (_ButtonStyle)
            {
                case ButtonStyles.Rectangle:
                    e.Graphics.FillRectangle(brush, newRect);
                    e.Graphics.DrawRectangle(new 
                        Pen(_NormalBorderColor, 1), newRect);
                    break;
                case ButtonStyles.Ellipse:
                    e.Graphics.FillEllipse(brush, newRect);
                    e.Graphics.DrawEllipse(new 
                      Pen(_NormalBorderColor, 1), newRect);
                    break;
    
            }
            e.Graphics.DrawString(this.Text, base.Font, 
               new SolidBrush(base.ForeColor), textX, textY);
            break;
    
        case _States.MouseOver:
            brush = new LinearGradientBrush(newRect, 
                  _HoverColorA, _HoverColorB, mode);
            switch (_ButtonStyle)
            {
                case ButtonStyles.Rectangle:
                    e.Graphics.FillRectangle(brush, newRect);
                    e.Graphics.DrawRectangle(new 
                         Pen(_HoverBorderColor, 1), newRect);
                    break;
                case ButtonStyles.Ellipse:
                    e.Graphics.FillEllipse(brush, newRect);
                    e.Graphics.DrawEllipse(new 
                       Pen(_HoverBorderColor, 1), newRect);
                    break;
    
            }
            e.Graphics.DrawString(this.Text, base.Font, 
              new SolidBrush(base.ForeColor), textX, textY);
            break;
    
        case _States.Clicked:
            brush = new LinearGradientBrush(newRect, 
                  _HoverColorA, _HoverColorB, mode);
            switch (_ButtonStyle)
            {
                case ButtonStyles.Rectangle:
                    e.Graphics.FillRectangle(brush, newRect);
                    e.Graphics.DrawRectangle(new 
                         Pen(_HoverBorderColor, 2), newRect);
                    break;
                case ButtonStyles.Ellipse:
                    e.Graphics.FillEllipse(brush, newRect);
                    e.Graphics.DrawEllipse(new 
                       Pen(_HoverBorderColor, 2), newRect);
                    break;
    
            }
            e.Graphics.DrawString(this.Text, base.Font, 
              new SolidBrush(base.ForeColor), 
              textX + 1, textY + 1);
            break;
    }

    另一个控制项目 ProgressBar颜色。 反馈 请为这篇文章投票。 如果你有,请给我发邮件或留下你的信息: 错误报告 代码的改进 任何意见或建议。 本文转载于:http://www.diyabc.com/frontweb/news457.html

  • 相关阅读:
    Java正则表达式
    FlashFXP 5.0.0官方中文破解版,附文件下载地址和破解码
    【转】推荐!国外程序员整理的Java资源大全
    有线网卡和无线网卡同时使用
    Shell脚本传递带有空格的参数
    Ubuntu 14.04下MySQL服务器和客户端的安装
    python 读取不同的列,判断然后将结果写入excel
    tps qps
    python ddt 实现数据驱动一
    JMeter入门:04Java Request实例
  • 原文地址:https://www.cnblogs.com/Dincat/p/13450160.html
Copyright © 2011-2022 走看看