3

I'm working on a .NET 3.5 desktop application written in C#. It's complex UI is populated dynamically. One part of it is the following group box which is contained in a FlowLayoutPanel and the FlowLayoutPanel is contained in a UserControl. The screenshot is taken from the design view:

enter image description here

When I launch the application, all controls get stretched:

enter image description here

Even I'm fixing the widths of each UserControl's size when Load event of the UserControl is called. The AutoSize property of all of the controls inside the group box is false.

Why is this happening and how to prevent this? I want the UI look exactly like the design view.

EDIT

The best answer to this question didn't solve my problem. Firstly, setting the border style to FixedX creates an undesirable border. Secondly, the inner controls still expanded and they are clipped by the border.

Community
  • 1
  • 1
Donotalo
  • 12,748
  • 25
  • 83
  • 121
  • 1
    Why are you using a flow layout panel when you don't want the controls to flow? Wouldn't a table layout panel be more appropriate? Or even just a normal panel with anchors? – Luaan Sep 16 '16 at 06:19
  • I need the flow layout panel because there is another panel inside the flow layout panel on top of this group box. That panel needs to be hidden based on user input. I need all controls below that panel to be shifted upward when that happens. – Donotalo Sep 16 '16 at 06:23
  • Possible duplicate of [c# how to prevent user from resizing my application window?](http://stackoverflow.com/questions/3750804/c-sharp-how-to-prevent-user-from-resizing-my-application-window) – Mafii Sep 16 '16 at 06:31
  • 1
    It's not a duplicate. User isn't resizing the window. For my case, the controls get stretched automatically! – Donotalo Sep 16 '16 at 06:36
  • So you put the table panel inside of the flow panel. That's the whole point of the layouting panels. Also, while the user isn't resizing the form, you are most likely resizing the user control. – Luaan Sep 16 '16 at 07:09
  • The layout of controls on your form is unclear and it makes the question like a guess game. It's better to post a code or image or something which shows the layout and settings of controls to help us to help you :) – Reza Aghaei Sep 16 '16 at 07:20
  • @RezaAghaei: I've tried many different things today so couldn't response in time. I tried putting everything in a table layout panel as CodeJoy suggested. I didn't solve my problem. The deadline is approaching so it's difficult (in terms of time) for me to find out a minimal code that would recreate this problem. Screenshot I've shared is part of a much larger design where most of the controls are dynamically populated. I thought that I missed some easy property to check so that controls don't get stretched strangely. Apparently that's not the case. – Donotalo Sep 16 '16 at 10:49

5 Answers5

5

Make AutoScaleMode "Inherit" for all children user control.

abidsplanet
  • 510
  • 5
  • 10
  • ...And make sure that Visual Studio hasn't set the usercontrol autoscalemode to .font in the usercontrol.designer.cs for the usercontrol. – ainwood Apr 02 '20 at 04:40
1

You can play in the Anchor property

  1. If you want to keep the Label in its place as the design => use combination : Top, Left
  2. If you want to stretch the control horizontally => use combination : Top, Left , Right
  3. If you want to keep the control to stretch the control in all directions => use combination : Top, Left, Right, Bottom
  4. If you want to keep the control in the Bottom right position ( usually used for buttons) => use combination: Bottom, Right

You might read more about Anchor here and here

Hope this will help you

Monah
  • 6,714
  • 6
  • 22
  • 52
0

Set the WrapContents property of your FlowLayoutPanel to true

Please notify my if this worked or not

Pepernoot
  • 3,409
  • 3
  • 21
  • 46
0

Check EnableVisualStyles property value set at application level. Set it to true and check.

0

If your button gets wider when you enlarge its container object, the button must be surely anchored to the left and right borders of the container. Just anchor it to the top or bottom, but not to the left or right borders. Conversely, if your button gets higher, don't anchor it to the top or bottom.

Fabian
  • 19
  • 3