0

How can I set the size of a WinForms Window to Auto! I do not want to give it a specific size, want it to adjust to its content!

For example in WPF we have something like this:

Height="Auto" Width="420" SizeToContent="Height"

The reason I want to set it this way is that the window shrinks in Windows 10 on 4k resolution!

Vahid
  • 5,144
  • 13
  • 70
  • 146
  • There is no similar behavior for WinForms (AFAIK). What you can do is to read the Screen size and apply some kind of calc to set your Height and Width – Steve Feb 02 '17 at 13:11
  • @Steve That is what I feared! – Vahid Feb 02 '17 at 13:14
  • Well, that's just the tip of the iceberg. Other problems are waiting here. For example font-size – Steve Feb 02 '17 at 13:15
  • @Steve I know! I'm working a legacy code which was written before WPF! – Vahid Feb 02 '17 at 13:17
  • 1
    Sorry for that first post ... try this link [it is from code behind but it can help u](http://stackoverflow.com/questions/25426930/how-can-i-set-wpf-window-size-is-25-percent-of-relative-monitor-screen) – Patrik Kučera Feb 02 '17 at 13:24
  • Use the form's AutoSize and AutoSizeMode properties. But surely you are [ignoring the real reason](http://stackoverflow.com/questions/13228185/how-to-configure-an-app-to-run-correctly-on-a-machine-with-a-high-dpi-setting-e/13228495#13228495). – Hans Passant Feb 02 '17 at 15:23

0 Answers0