自制控件

来源:互联网 发布:淘宝网针织杉时腰 编辑:程序博客网 时间:2024/06/10 05:50
protected override void OnPaintBackground(PaintEventArgs e) { Rectangle r = new Rectangle(0, 0, this.Size.Width, this.Size.Height); LinearGradientBrush lb = new LinearGradientBrush(r, Color.Red, Color.Yellow, LinearGradientMode.BackwardDiagonal); e.Graphics.FillRectangle(lb, r);//使用画刷填充指定区域 } protected override void OnPaint(PaintEventArgs e) { e.Graphics.DrawBezier(curvepen, pt1, pt2, pt3, pt4);//画四个圆点代表每个点 e.Graphics.DrawEllipse(curvepen, pt1.X - 1, pt1.Y - 1, 3, 3); e.Graphics.DrawEllipse(curvepen, pt2.X - 1, pt2.Y - 1, 3, 3); e.Graphics.DrawEllipse(curvepen, pt3.X - 1, pt3.Y - 1, 3, 3); e.Graphics.DrawEllipse(curvepen, pt4.X - 1, pt4.Y - 1, 3, 3); base.OnPaint(e); }例程里面的东西疑惑的地方在 base.OnPaint(e);base.OnpaintBackground(e); 若是在onpaintbackground中加入base.OnpaintBackground(e);则在运行后form的background没有改变颜色删掉都能够显示修改的信息在onpaint中 base.OnPaint(e);存在与否则没有对于绘制的贝塞尔曲线有影响