-2

I have a problem to round a picturebox's edges on visual studio enterprise 2015. I am using this code:

private void pictureBox3_Click(object sender, EventArgs e)
{
    System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
    gp.AddEllipse(0, 0, pictureBox1.Width - 3, pictureBox1.Height - 3);
    Region rg = new Region(gp);
    pictureBox1.Region = rg;
}

Nothing happens when I run this code..

TaW
  • 53,122
  • 8
  • 69
  • 111

2 Answers2

0

Try this way once I think it would work.

Rectangle r = new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height);
System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
int d = 50;
gp.AddArc(r.X, r.Y, d, d, 180, 90);
gp.AddArc(r.X + r.Width - d, r.Y, d, d, 270, 90);
gp.AddArc(r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90);
gp.AddArc(r.X, r.Y + r.Height - d, d, d, 90, 90);
pictureBox1.Region = new Region(gp);
Navoneel Talukdar
  • 4,393
  • 5
  • 21
  • 42
0

The code works just fine.

But you may be mixing up pictureBox1 and pictureBox3.

Or maybe the click event is not hooked up ..

For using a rounded rectangle instead of an ellipse look at Neel's answer!

Community
  • 1
  • 1
TaW
  • 53,122
  • 8
  • 69
  • 111