Border on generic Control or Panel?

  • Thread starter Thread starter Wade
  • Start date Start date
W

Wade

Okay ... I'm frustrated. I can create a backcolor for a control or panel,
but I can't create a border. How can I do this?

The only way I've found is to stack on panel over another, with the back
panel set to black and slighly bigger than the panel that sits on it, which
is set to white.

Help? Thanks!
 
Nevermind ... found a great solution -- thanks chris-s.

public class IFrame : System.Windows.Forms.Panel
{
private BorderStyle _BorderStyle;

public IFrame()
{
_BorderStyle = BorderStyle.FixedSingle;
}

public BorderStyle BStyle
{
get { return this._BorderStyle; }
set { this._BorderStyle = value; Invalidate(); }
}

protected override void OnPaint(PaintEventArgs pea)
{
base.OnPaint(pea);

using (Pen pe = new Pen(Color.Black))
{
switch (this.BStyle)
{
case BorderStyle.FixedSingle:

pea.Graphics.DrawRectangle(pe, 0, 0, this.Width - 1,
this.Height - 1);
break;

case BorderStyle.Fixed3D:

pea.Graphics.DrawRectangle(pe,
this.ClientRectangle);
break;

case BorderStyle.None:

break;
}
}
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top