Is there a way to create non-rectangular pictureBoxes. I have round shapes that should overlap and if possible should be in different pictureboxes.. I tried the this here, but you could not see both pictureboxes that are overlapping at a time, but just one..
Asked
Active
Viewed 400 times
0
-
2Don't use any controls. Try drawing straight into your container-- make sure it's double-buffered. – LarsTech Nov 20 '14 at 16:25
-
I guess you could use GraphicPath to "crop" your pictureboxes by creating a custom transparent mask. http://stackoverflow.com/questions/1967944/how-to-draw-a-rounded-rectangle-with-winforms-net – Grigory Kornilov Nov 20 '14 at 16:26
-
It's doable using [path](http://msdn.microsoft.com/en-us/library/system.windows.shapes.path%28v=vs.110%29.aspx) if you're using WPF. – Scott Solmer Nov 20 '14 at 16:29
1 Answers
1
You can make the PictureBoxes circular by adding an Ellipse to a GraphicsPath and then building a new Region from it.
Here's a quick example:
public class Target : PictureBox
{
public Target()
{
this.Size = new Size(100, 100);
this.Paint += Target_Paint;
Rectangle rc = this.ClientRectangle;
rc.Inflate(-10, -10);
System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
gp.AddEllipse(rc);
this.Region = new Region(gp);
}
void Target_Paint(object sender, PaintEventArgs e)
{
Rectangle rc = this.ClientRectangle;
rc.Inflate(-10, -10);
using (Pen pen = new Pen(Color.Blue, 5))
{
e.Graphics.DrawEllipse(pen, rc);
}
rc = new Rectangle(new Point(this.Size.Width / 2, this.Size.Height / 2), new Size(1, 1));
rc.Inflate(9, 9);
e.Graphics.FillEllipse(Brushes.Red, rc);
}
}
After compiling, the new control appears at the top of your ToolBox.
Here's a screenshot with three of them overlapping each other:

Idle_Mind
- 38,363
- 3
- 29
- 40