I used an advise from this topic: Rounded edges in picturebox C# to make my picturebox edges rounded. So, I claimed a new control using this code:
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
class OvalPictureBox : PictureBox {
public OvalPictureBox() {
this.BackColor = Color.DarkGray;
}
protected override void OnResize(EventArgs e) {
base.OnResize(e);
using (var gp = new GraphicsPath()) {
gp.AddEllipse(new Rectangle(0, 0, this.Width-1, this.Height-1));
this.Region = new Region(gp);
}
}
}
But there is my question: how could I add antialias to my control? I read some topics like this: Possible to have anti-aliasing when drawing a clipped image? but there is just drawing functions are used, and I need to implement antialias in my own control, which parent is PictureBox.
I also tried to override OnPaint method to get PaintEventArgs to use the SmoothingMode, but my code sucked and didn`t work properly. So I deleted it and this is what I have now:
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
using (var gp = new GraphicsPath())
{
gp.AddEllipse(new Rectangle(0, 0, this.Width - 1, this.Height - 1));
this.Region = new Region(gp);
}
}
What should I add to this method?