简体   繁体   中英

How to draw rectangle with solid border?

I use an answer from How do i make a picturebox selectable? to make PictureBox selectable.

All works, but lines of border rectangle are dashed. How can I make it solid?

It it because

      ControlPaint.DrawFocusRectangle(pe.Graphics, rc);

is drawing a dashed rectangle.

To draw a solid rectangle use:

protected override void OnPaint(PaintEventArgs pe)
{
  base.OnPaint(pe);
  if (this.Focused)
  {
    var rc = this.ClientRectangle;
    rc.Inflate(-2, -2);
    pe.Graphics.DrawRectangle(Pens.Black, rc);
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM