public class WindowOne:Form { public WindowOne() { InitializeCompnent(); } public void InitializeCompnent() { this.Width = 200; this.Height = 200; } //冲毁window 方法 private void ReDraw(Graphics g) { Random ran = new Random(); //Color ranColor = Color.FromArgb(ran.Next(256), ran.Next(256) // , ran.Next(256), ran.Next(256)); Color ranColor = Color.FromArgb(100, ran.Next(256) , ran.Next(256), ran.Next(256)); g.Clear(ranColor); } /// <summary> /// 窗体绘制 事件 /// </summary> /// <param name="e"></param> protected override void OnPaint(PaintEventArgs e) { //base.OnPaint(e); ReDraw(e.Graphics); } /// <summary> /// 窗体大小 重置 /// </summary> /// <param name="e"></param> protected override void OnResize(EventArgs e) { //强制重新绘制 this.Invalidate(); } }
显示结果: