Set panel border thickness in C # winform

I have a search and the result cannot solve my case. Actually, I have a panel, and I want the panel to have a denser border than Windows. I need a BorderStyle

BorderStyle.FixedSingle

fatter .. thanks before

+4
source share
2 answers

You must customize your own Panelwith a small custom picture:

//Paint event handler for your Panel
private void panel1_Paint(object sender, PaintEventArgs e){ 
  if(panel1.BorderStyle == BorderStyle.FixedSingle){
     int thickness = 3;//it up to you
     int halfThickness = thickness/2;
     using(Pen p = new Pen(Color.Black,thickness)){
       e.Graphics.DrawRectangle(p, new Rectangle(halfThickness,
                                                 halfThickness,
                                                 panel1.ClientSize.Width-thickness,
                                                 panel1.ClientSize.Height-thickness));
     }
  }
}

Here is a screenshot of the panel with a thickness 30:

Screen shot of panel with border thickness of 30

NOTE . The size is Rectanglecalculated in the middle of the line of the drawing, suppose you draw a line with a thickness 4, there will be an offset of 2 outside and 2 inside.

, Mr Hans, SizeChanged panel1 :

private void panel1_SizeChanged(object sender, EventArgs e){
   panel1.Invalidate();
}

ResizeRedraw = true Reflection SizeChanged, :

typeof(Control).GetProperty("ResizeRedraw", BindingFlags.NonPublic | BindingFlags.Instance)
               .SetValue(panel1, true, null);

, , doubleBuffered 1:

typeof(Panel).GetProperty("DoubleBuffered",
                          BindingFlags.NonPublic | BindingFlags.Instance)
             .SetValue(panel1,true,null);
+14

, ( - ). .

0

All Articles