Leticia Esperon Leticia Esperon - 1 year ago 87
C# Question

How can I prevent a button from getting resized when adding user control to form?

I have a tab control and a user control with a button. When I add the user control to the tab with this code:

ProductImporters uc = new ProductImporters();
uc.Dock = DockStyle.Fill;

The button grows a lot. I've already tried setting the button with a max-size, auto-size in false, I tried fixing and locking it, nothing works.

The user control is the same size of the tab where it is going to be put in.

Any ideas are appreciated, thank you.

Answer Source

Instead of DockStyle.Fill use DockStyle.None. Use Anchoring to fix the position of the button. For example, anchor to right and bottom to fix it on the bottom right position. Set Autosize property of the button to false. This will avoid resize.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download