本文主要是介绍c#中控件重绘(放大缩小移动隐藏恢复后不消失)实例,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
//很重要,一定要重写并在在OnPaint()中用传入的pevent.Graphics重绘,并且屏蔽掉父类的OnPaint方法,这样重绘后的图形不论控件怎么操作都不会消失了
using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;namespace GMFast.UI.UserControls { public class EllipseButton:Button { //public class A // { // public int a = 9; // } // A a = new A(); // int b = a.a; //字段属性无法引用非静态属性、字段、方法 public EllipseButton() { //this.BackColor = Color.FromArgb(255, 255, 254); } public ColorStatus _colorStatus=ColorStatus.Empty; public ColorStatus colorStatus { get { return _colorStatus; } set { if (_colorStatus != value) { _colorStatus = value; this.Refresh(); } } } protected override void OnPaint(PaintEventArgs pevent) { Graphics g= pevent.Graphics; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //图片柔顺模式选择 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;//高质量 g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;//再加一点 g.FillRectangle(new SolidBrush(BackColorInsideDic[colorStatus]), new Rectangle(0, 0, this.Width, this.Height)); g.DrawEllipse(new Pen(BackColorCircleDic[colorStatus],4), new Rectangle(4, 4, this.Width - 8, this.Height - 8)); GraphicsPath gPath = new GraphicsPath(); // 绘制椭圆形区域 gPath.AddEllipse(2, 2, this.ClientSize.Width - 4,
这篇关于c#中控件重绘(放大缩小移动隐藏恢复后不消失)实例的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!