• 自定义控件绘制画圆


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.ComponentModel;
    
    namespace WindowsFormsApplication1
    {
        public class myButton:Panel
        {
            Control _preControl;
            Color _myBackColor;
    
            public Color MyBackColor
            {
                get { return _myBackColor; }
                set { _myBackColor = value;
                this.Invalidate();
                }
            }
            public Control PreControl
            {
                get { return _preControl; }
                set { _preControl = value;
                this.Invalidate();
                }
            }
            public myButton()
            {
                this.SetStyle(ControlStyles.AllPaintingInWmPaint |
                    ControlStyles.OptimizedDoubleBuffer |
                    ControlStyles.UserPaint|
                ControlStyles.SupportsTransparentBackColor|
                ControlStyles.ResizeRedraw, true);
                this.UpdateStyles();
                _myBackColor = Color.LightBlue;
            }
    
            protected override void OnPaint(PaintEventArgs pevent)
            {
                Graphics gp = pevent.Graphics;
                gp.SmoothingMode = SmoothingMode.AntiAlias;
                Rectangle rect=new Rectangle(0, 0, this.Width - 1, this.Height - 1);
                gp.DrawEllipse(new Pen(_myBackColor, 1),rect );
                LinearGradientBrush gb = new LinearGradientBrush(rect, Color.White, Color.Black, 0f);   //线性渐变
                gp.FillEllipse(gb, rect);     //线性渐变
                //gp.FillEllipse(new SolidBrush(_myBackColor), rect);       //单色画笔
                
            }
    
            #region 隐藏属性
            [Browsable(false)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
            public override Color BackColor
            {
                get
                {
                    return base.BackColor;
                }
                
            }
    
            #endregion
        }
    }
    你应该了解真相,真相使你自由!
  • 相关阅读:
    取石子(二)
    Nim游戏 之HDU 1850 Being a Good Boy in Spring Festival
    移动字母
    asterisk meetme 会议实现
    asterisk基础学习一
    Asterisk 1.8 sip 协议栈分析
    asterisk dialplan详解
    asterisk chan_sip.c代码分析
    asteirsk 开发指南
    asterisk 基础学习二
  • 原文地址:https://www.cnblogs.com/Hooper_he/p/9636812.html
Copyright © 2020-2023  润新知