问题描述
我在form窗体上模拟点阵屏,绘制了很多16*16的点阵,但是却不能清除,请问如果我想清除已经绘制好的点阵,我该怎么做呢?
解决方案
解决方案二:
你是怎么绘制的?
解决方案三:
画在控件上的,可以尝试控件的clear或者移除后再添加,form上就只能用背景色重新画一遍
解决方案四:
classDotScreen:Control{privateint_DotWidth=5;publicintDotWidth{get{return_DotWidth;}set{if(value==_DotWidth)return;_DotWidth=value;this.Height=0;this.Invalidate();}}privateSize_DotSize=newSize(10,10);publicSizeDotSize{get{return_DotSize;}set{if(value==_DotSize)return;_DotSize=value;this._DotSwitch=newbool[value.Width,value.Height];this.Height=0;this.Invalidate();}}privatebool[,]_DotSwitch=newbool[10,10];publicbool[,]DotSwitch{get{return_DotSwitch;}}publicDotScreen(){this.SetStyle(ControlStyles.ResizeRedraw,true);this.SetStyle(ControlStyles.OptimizedDoubleBuffer,true);this.SetStyle(ControlStyles.AllPaintingInWmPaint,true);this.SetStyle(ControlStyles.SupportsTransparentBackColor,true);}protectedoverridevoidSetBoundsCore(intx,inty,intwidth,intheight,BoundsSpecifiedspecified){width=this._DotWidth*this._DotSize.Width;height=this._DotWidth*this._DotSize.Height;base.SetBoundsCore(x,y,width,height,specified);}protectedoverridevoidOnPaint(PaintEventArgse){for(intx=0;x<this._DotSize.Width;x++){for(inty=0;y<this._DotSize.Height;y++){e.Graphics.FillEllipse(this._DotSwitch[x,y]?Brushes.Red:Brushes.Gray,x*this._DotWidth,y*this._DotWidth,this._DotWidth,this._DotWidth);}}base.OnPaint(e);}}
解决方案五:
classDotScreen:Control{privateint_DotWidth=10;[Description("点的大小")]publicintDotWidth{get{return_DotWidth;}set{if(value==_DotWidth)return;_DotWidth=value;this.Height=0;//触发SetBoundsCorethis.Invalidate();}}privateSize_DotSize=newSize(10,10);[Description("点阵尺寸")]publicSizeDotSize{get{return_DotSize;}set{if(value==_DotSize)return;_DotSize=value;this._DotSwitch=newbool[value.Width,value.Height];this.Height=0;this.Invalidate();}}privatebool[,]_DotSwitch=newbool[10,10];[Description("点阵开关")]publicbool[,]DotSwitch{get{return_DotSwitch;}}publicDotScreen(){this.SetStyle(ControlStyles.ResizeRedraw,true);this.SetStyle(ControlStyles.OptimizedDoubleBuffer,true);this.SetStyle(ControlStyles.AllPaintingInWmPaint,true);this.SetStyle(ControlStyles.SupportsTransparentBackColor,true);}//固定控件尺寸protectedoverridevoidSetBoundsCore(intx,inty,intwidth,intheight,BoundsSpecifiedspecified){width=this._DotWidth*this._DotSize.Width;height=this._DotWidth*this._DotSize.Height;base.SetBoundsCore(x,y,width,height,specified);}protectedoverridevoidOnPaint(PaintEventArgse){for(intx=0;x<this._DotSize.Width;x++){for(inty=0;y<this._DotSize.Height;y++){e.Graphics.FillEllipse(this._DotSwitch[x,y]?Brushes.Red:Brushes.Gray,x*this._DotWidth,y*this._DotWidth,this._DotWidth,this._DotWidth);}}base.OnPaint(e);}}
注释往加上了如果不想自己手动刷新那就自己做索引器修改DotSwitch后在控件内部自己刷新