Hi,
I need to have a hollow (any shape for example a circle) inside a Windows Forms form?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Selva GanapathyRank #560 · 4.3K reputationPosted Mar 11, 2014, 1:45 AM EDT
You can use "TransparencyKey" property to make any shapes or text hollow in a form as per the following code. Use a shape and fill a color and assign the same color to TransparencyKey property of the form.
namespace Hollow_Form
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.TransparencyKey = Color.Orange;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
var text = "?????"; //I am using Tamil text here
e.Graphics.DrawString(text, this.Font, Brushes.Orange, new PointF(10, 10));
e.Graphics.FillEllipse(Brushes.Orange, new Rectangle(100, 100, 100, 100));
}
}
}
Output Screen:
Regards,
Selva Ganapathy K
Shweta LodhaRank #31 · 39.8K reputationPosted Mar 10, 2014, 9:58 AM EDT
Sample code to generate a circle inside rectangle:
System.Drawing.Graphics graphics = this.CreateGraphics();
System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle( 50, 50, 150, 150);
graphics.DrawEllipse(System.Drawing.Pens.Black, rectangle);
graphics.DrawRectangle(System.Drawing.Pens.Red, rectangle);
You can get more information on:
http://msdn.microsoft.com/en-us/library/sfwzeec0(v=vs.90).aspx