0
votes

I have a WinForms application with a GroupBox in it. I have designed a user control which groups together a bunch of textboxes and other controls so that I can apply some custom logic to them. The user control looks like the following: User control

I want to place this user control within my GroupBox, however doing so ends up affecting the layout of the controls within my user control (see below). User control in groupbox

As you can see, my textboxes are all spread out and resized from how I want them to be. If I place this control directly on the main form or in a Panel (not in the GroupBox) the layout is maintained, however the moment I place it in the GroupBox everything gets messed up. Is there a way to fix this problem?

2

2 Answers

0
votes

The user control seems to have a different size in the two cases. Make sure it has the same size in the group box as when you place it directly on the form. If you have used a layouting control like a FlowLayoutPanel or a TableLayoutPanel, this might be of importance.

Also be aware that winforms controls inherit properties from their parent if they are not set explicitly. E.g., if you have not set the font property of the user control and its text boxes, those will be taken from the group box.

0
votes

What ended up working for me was making a separate class MyGroupBox which extends GroupBox. The class is empty, but I converted the GroupBox on my form to this and placed the user control inside, which solved the problem.