Leticia Esperon Leticia Esperon - 7 months ago 57
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.


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.