Сглаживание круглого Picturebox - C# private void Form1_Load(object sender, EventArgs e) { System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddEllipse(0, 0, 100, 100); Region rgn = new Region(path); pictureBox2.Region = rgn; pictureBox2.BackColor = System.Drawing.SystemColors.GrayText; } [/[B]code[/B]] Как сгладить?[/SIZE][/B] Код private void Form1_Load(object sender, EventArgs e) { System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddEllipse(0, 0, 100, 100); Region rgn = new Region(path); pictureBox2.Region = rgn; pictureBox2.BackColor = System.Drawing.SystemColors.GrayText; } [/[B]code[/B]] Как сгладить?[/SIZE][/B]
Я погуглил и внятного решения не нашел. Но если ваш PictureBox будет лежать непосредственно на форме и под ним не будет никаких контролов, то можете немного считерить и сделать так: private void Form1_Load(object sender, EventArgs e) { System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddEllipse(0,0, pictureBox1.Width, pictureBox1.Height); Region rgn = new Region(path); pictureBox1.Region = rgn; pictureBox1.BackColor = System.Drawing.SystemColors.GrayText; Graphics gr = Graphics.FromImage(pictureBox1.Image); gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; gr.DrawEllipse(new Pen(this.BackColor, 2), 0, 0, pictureBox1.Width, pictureBox1.Height); } Код private void Form1_Load(object sender, EventArgs e) { System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddEllipse(0,0, pictureBox1.Width, pictureBox1.Height); Region rgn = new Region(path); pictureBox1.Region = rgn; pictureBox1.BackColor = System.Drawing.SystemColors.GrayText; Graphics gr = Graphics.FromImage(pictureBox1.Image); gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; gr.DrawEllipse(new Pen(this.BackColor, 2), 0, 0, pictureBox1.Width, pictureBox1.Height); }
Вот класс, которые подходит под любые элементы, нужно просто закинуть котрол и указать нужные углы, класс делал я public static void SetRoundedShape(Control control, int radius, bool topRight, bool topLeft, bool bottomLeft, bool bottomRight) { try { GraphicsPath path = new GraphicsPath(); if (topRight) { path.AddLine(radius, 0, control.Width - radius, 0); path.AddArc(control.Width - radius, 0, radius, radius, 270, 90); } else path.AddLine(0, 0, control.Width, 0); if (bottomRight) { path.AddLine(control.Width, radius, control.Width, control.Height - radius); path.AddArc(control.Width - radius, control.Height - radius, radius, radius, 0, 90); } else path.AddLine(control.Width, 0, control.Width, control.Height); if (bottomLeft) { path.AddLine(control.Width - radius, control.Height, radius, control.Height); path.AddArc(0, control.Height - radius, radius, radius, 90, 90); } else path.AddLine(control.Width, control.Height, 0, control.Height); if (topLeft) { path.AddLine(0, control.Height - radius, 0, radius); path.AddArc(0, 0, radius, radius, 180, 90); } else path.AddLine(0, control.Height, 0, 0); control.Region = new Region(path); Console.WriteLine("Элемент " + control.Name + " был прорисован."); } catch (Exception e) { Console.WriteLine("При прорисовке элемента: " + control.Name + " Произошла ошибка: " + e ); } } CSHARP public static void SetRoundedShape(Control control, int radius, bool topRight, bool topLeft, bool bottomLeft, bool bottomRight) { try { GraphicsPath path = new GraphicsPath(); if (topRight) { path.AddLine(radius, 0, control.Width - radius, 0); path.AddArc(control.Width - radius, 0, radius, radius, 270, 90); } else path.AddLine(0, 0, control.Width, 0); if (bottomRight) { path.AddLine(control.Width, radius, control.Width, control.Height - radius); path.AddArc(control.Width - radius, control.Height - radius, radius, radius, 0, 90); } else path.AddLine(control.Width, 0, control.Width, control.Height); if (bottomLeft) { path.AddLine(control.Width - radius, control.Height, radius, control.Height); path.AddArc(0, control.Height - radius, radius, radius, 90, 90); } else path.AddLine(control.Width, control.Height, 0, control.Height); if (topLeft) { path.AddLine(0, control.Height - radius, 0, radius); path.AddArc(0, 0, radius, radius, 180, 90); } else path.AddLine(0, control.Height, 0, 0); control.Region = new Region(path); Console.WriteLine("Элемент " + control.Name + " был прорисован."); } catch (Exception e) { Console.WriteLine("При прорисовке элемента: " + control.Name + " Произошла ошибка: " + e ); } }
интересно, но IsHighlighted не существует в текущем контексте, но я тут за дизайном кнопок так что годно