3

I'm currently designing a program in "Visual Studio 2015 C#" and would like to implement circular picture boxes. In the program there are picture boxes which source image is downloaded from the web. In it's default state, the "picturebox" is square. I would like to know how I could change the shape of the "picturebox" to a circle. That way the image when loaded will be circular instead of squared or rectangular.

I already figured out how to downscale the image and keep it's quality and center it, but I do not know how to change the "picturebox" into a circle.

I found a couple ways to do it, but unfortunately with this methods the circle is not smooth, instead it is pixelated.

This is an example of what I would like: https://i.stack.imgur.com/ecjAq.png

Jose Cancel
  • 151
  • 1
  • 2
  • 15
  • What methods did you find then? Maybe they can be improved. – Matti Virkkunen Feb 27 '16 at 20:11
  • Regions are not anti-aliased when they are painted, it is not an available option. That tends to be noticeable on the 96 dpi monitor of yesterday. Perhaps you ought to get ahead by making the Image circular instead of the control. – Hans Passant Feb 27 '16 at 22:27

1 Answers1

5

You create a path (that is a circle, or whatever shape you want), and set the picturebox region to that path. Here's an example with a circle:

 public partial class Form1 : Form {
     public Form1() {
       InitializeComponent();
       System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
       path.AddEllipse(0, 0, pictureBox1.Width, pictureBox1.Height);
       pictureBox1.Region = new Region(path);
     }
   }

This StackExchange post has how to make any path smooth for a picturebox:

Possible to have anti-aliasing when drawing a clipped image?

Community
  • 1
  • 1
Baronz
  • 667
  • 5
  • 16
  • 1
    That's pretty much the method I was using. The problem is that the circle produced with this method is pixelated. Example: http://i.imgur.com/E1TiYZX.png (The image in the right is the original. This is exactly what I wish to do, but with a smooth circle.) – Jose Cancel Feb 27 '16 at 20:26
  • Hmm... no idea, let me tinker for a few – Baronz Feb 27 '16 at 20:57