In the properties of a Panel
I have set the border style to Fixed Single
.
When I am running my application it has the color gray. I don't know how to change the border color.
I have tried this in the Paint
event handler of the panel:
private void HCp_Paint(object sender, PaintEventArgs e)
{
Panel p = sender as Panel;
ControlPaint.DrawBorder(e.Graphics, p.DisplayRectangle, Color.Yellow, ButtonBorderStyle.Inset);
}
This displays the border like this:
but I want a fixed single border like this:
How I make the border in yellow?
If you don't want to make a custom panel as suggested in @Sinatr's answer you can draw the border yourself:
private void panel1_Paint(object sender, PaintEventArgs e) { ControlPaint.DrawBorder(e.Graphics, this.panel1.ClientRectangle, Color.DarkBlue, ButtonBorderStyle.Solid); }
You can create own Panel
class and draw border in the client area:
[System.ComponentModel.DesignerCategory("Code")]
public class MyPanel : Panel
{
public MyPanel()
{
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
}
protected override void OnPaint(PaintEventArgs e)
{
using (SolidBrush brush = new SolidBrush(BackColor))
e.Graphics.FillRectangle(brush, ClientRectangle);
e.Graphics.DrawRectangle(Pens.Yellow, 0, 0, ClientSize.Width - 1, ClientSize.Height - 1);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With