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);
if (drawRectangle.Width < 1) drawRectangle.Width = 1;
if (drawRectangle.Height < 1) drawRectangle.Height = 1;
g.FillEllipse(new SolidBrush(darkColor), drawRectangle);
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);
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(drawRectangle);
g.SetClip(gp);
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);
float w = drawRectangle.Width;
g.SetClip(this.ClientRectangle);
}
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...