Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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;
C#
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);
}


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...
Posted

1 solution

 
Share this answer
 
Comments
Umut Comlekcioglu 24-May-13 18:21pm    
Thanks for answer.But;
How i do transparent this control backcolor?
And my second problem is, I have a two Custom Control (Polygon and Checker).
While program is running and "Checker" bring to front "Polygon" , again, graphic is disperse.
Sergey Alexandrovich Kryukov 24-May-13 18:30pm    
Please see my recent answer:
http://www.codeproject.com/Answers/596350/TransparentplusbackgroundplusinplusPictureBox#answer1
And I already answered on disperse...
—SA
Umut Comlekcioglu 24-May-13 18:49pm    
I wonder, I send the project and you are check it please.I'm almost read all blog but still continue the problem.Thanks for help, I'm work this problem a long time...
http://turbobit.net/7dqw98vzl152.html
Sergey Alexandrovich Kryukov 24-May-13 20:38pm    
I cannot promise anything certain...
—SA
Umut Comlekcioglu 25-May-13 5:11am    
Okey, thanks for help, I'm grateful you, enough to try... :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900