0

I am manually resizing a GroupBox based on its content. To give it the proper size, it needs to be Content.Size + Border.Size.

How do I figure out what the size of the GroupBox border is?

Rick de Water
  • 2,388
  • 3
  • 19
  • 37
  • Why don't you set the `GroupBox`'s `ClientSize` property? It should do all that's necessary to take the border size into account by making sure that the size of the client area matches the size you gave. And why not use the `AutoSize` property in the first place? – Thorsten Dittmar Jun 07 '16 at 09:15
  • Why not simply `AutoSize = true`? Though I recall [why](http://stackoverflow.com/q/18308883/1997232). – Sinatr Jun 07 '16 at 09:18
  • Please, have a look at `System.Windows.Forms.SystemInformation` class – Dmitry Bychenko Jun 07 '16 at 09:27
  • Extend group box add `BorderThickness` and override `Paint` event and just like [here](http://stackoverflow.com/questions/76455/how-do-you-change-the-color-of-the-border-on-a-group-box) change `width` in `DrawLine` – mohsen Jun 07 '16 at 09:28

1 Answers1

1

You can use the DisplayRectangle property as a base for the calculations:

var bounds = groupBox.Bounds;
var displayRect = groupBox.DisplayRectangle;
var borderSize = new Size(bounds.Width - displayRect.Width, bounds.Height - displayRect.Height);
Ivan Stoev
  • 195,425
  • 15
  • 312
  • 343