• 自定义按钮与颜色和形状


    介绍 这是我第一个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

  • 相关阅读:
    html5+css3兼容问题小结
    webkit滚动条样式设置
    rem彻底研究
    四月、五月开发总结
    php oci8 小试
    oracle创建dblink
    php 页面参数过多时自动拼接get参数的函数
    Oracle Database 11g Express Edition 使用小结(windows)
    php sortable 动态排序
    php动态生成一个xml文件供swf调用
  • 原文地址:https://www.cnblogs.com/Dincat/p/13450160.html
Copyright © 2020-2023  润新知