本文介绍了用户控制OnPaint事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想画一次Image,我在用户控制(Checker)中使用这个图像。 如果有必要,我是发送到project.Please帮助我... 我正在创建一个用户控件(Checker),我在OnPaint Event中使用该代码; Hi,I want to draw Image one time and I''m use this Image in User Control(Checker).If necessary, I''m send to project.Please help me...I''m create a User Control(Checker), I''m use that code in the OnPaint Event;protected override void OnPaint(PaintEventArgs e){ base.OnPaint(e); Bitmap a = new Bitmap(50, 50); Graphics g = e.Graphics; using (g = Graphics.FromImage(a)) { g.SmoothingMode = SmoothingMode.AntiAlias; g.PixelOffsetMode = PixelOffsetMode.HighQuality; drawControl(g); e.Graphics.DrawImageUnscaled(a, 0, 0); }}private void drawControl(Graphics g){ Color lightColor = this.DarkColor; Color darkColor = this.DarkDarkColor; Rectangle paddedRectangle = new Rectangle(this.Padding.Left, this.Padding.Top, this.Width - (this.Padding.Left + this.Padding.Right), this.Height - (this.Padding.Top + this.Padding.Bottom)); int width = (paddedRectangle.Width < paddedRectangle.Height) ? paddedRectangle.Width : paddedRectangle.Height; Rectangle drawRectangle = new Rectangle(paddedRectangle.X, paddedRectangle.Y, width, width); // Draw the background ellipse if (drawRectangle.Width < 1) drawRectangle.Width = 1; if (drawRectangle.Height < 1) drawRectangle.Height = 1; g.FillEllipse(new SolidBrush(darkColor), drawRectangle); // Draw the glow gradient GraphicsPath path = new GraphicsPath(); path.AddEllipse(drawRectangle); PathGradientBrush pathBrush = new PathGradientBrush(path); pathBrush.CenterColor = lightColor; pathBrush.SurroundColors = new Color[] { Color.FromArgb(150, lightColor) }; g.FillEllipse(pathBrush, drawRectangle); // Set the clip boundary to the edge of the ellipse GraphicsPath gp = new GraphicsPath(); gp.AddEllipse(drawRectangle); g.SetClip(gp); // Draw the white reflection gradient GraphicsPath path1 = new GraphicsPath(); Rectangle whiteRect = new Rectangle(drawRectangle.X - Convert.ToInt32(drawRectangle.Width * .15F), drawRectangle.Y - Convert.ToInt32(drawRectangle.Width * .15F), Convert.ToInt32(drawRectangle.Width * .8F), Convert.ToInt32(drawRectangle.Height * .8F)); path1.AddEllipse(whiteRect); PathGradientBrush pathBrush1 = new PathGradientBrush(path); pathBrush1.CenterColor = Color.FromArgb(150, 255, 255, 255); pathBrush1.SurroundColors = new Color[] { Color.FromArgb(0, 255, 255, 255) }; g.FillEllipse(pathBrush1, whiteRect); // Draw the border float w = drawRectangle.Width; g.SetClip(this.ClientRectangle);} 我在My Other User Control(Board)中使用鼠标移动此控件但是,控制正在移动,图形分散。 如何修复它? 我想绘制图像而我正在使用此图像在用户控制(检查器)。 如果有必要,我发送到project.Please帮助我... I''m move this control with mouse in the My other User Control(Board) but, while this control is moving , graphic is disperse.How can fix it?I want to draw Image and I''m use this Image in User Control(Checker).If necessary, I''m send to project.Please help me...推荐答案 这篇关于用户控制OnPaint事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-23 11:11