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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Selva GanapathyPosted Mar 11, 2014, 5:45 AM
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 LodhaPosted Mar 10, 2014, 1:58 PM
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