19

enter image description here

My application looks good with 100% DPI setting, but when user selects different (125% or 150%) words don't fit in containers. I tried to fix this with solution I found here: Detect windows font size (100%, 125%, 150%) which is:

this.AutoScaleMode = AutoScaleMode.Dpi;

It fixed 150% setting (made it a little blur, but that's ok), unfortunately it didn't make the same for 125% which is being used on the PC the app is intended to run.

Is there some easy fix to this or do I have to rearrange every form manually?

Community
  • 1
  • 1
Bartosz Karpiński
  • 467
  • 1
  • 5
  • 15
  • 1
    See http://stackoverflow.com/questions/4075802/creating-a-dpi-aware-application – stuartd Sep 27 '14 at 10:24
  • 1
    At 150%, Windows takes over the scaling and will let your window draw itself into a bitmap. It then renders that bitmap to the screen, rescaling it to make it bigger. Yes, that looks fuzzy, you have to declare yourself [dpiAware](http://stackoverflow.com/a/13228495/17034) to stop that. You are definitely not DPI aware however, you somehow stopped the controls from properly rescaling themselves. Like they normally do, a screenshot is never a good way to show a coding problem. Might have something to do with the form's Font property, don't assign it. – Hans Passant Sep 27 '14 at 10:39
  • @HansPassant I changed font size in form to 12, is this causing problems? – Bartosz Karpiński Sep 27 '14 at 10:46

1 Answers1

13

Creating a DPI-Aware Application

All containers must use the same AutoScaleMode - this part fixed my problem

It is required that windows app should have same layout at different resolutions means there should be no effect on layout of app on changing resolution. Here are the steps to do this.

  1. Use table layout panel
  2. Drag control in cell of tablelayoutpanel and set anchor and dock property.
  3. Set rowspan and colspan properties of dragged control to merge cells
  4. Set margin and padding of dragged control with respect to cell.
  5. drag all controls and follow same steps, complete design using tablelayoutpanel
  6. Now set all columns and rows size of tablelayoutpanel = autosize (or in %)
  7. Set tablelayoutpanel properties autosize = true,autosizemode = grow and shrink
  8. Set Forms properties autosize = true,autosizemode = grow and shrink
  9. Run windows app If your windows app opens in maximum state then set tablelayoutpanel dock property =fill.
Community
  • 1
  • 1
Bartosz Karpiński
  • 467
  • 1
  • 5
  • 15
  • 2
    If you use table layout panel and set margin and padding, you [might be in for a bad time](https://support.microsoft.com/en-us/help/3044516/nested-tablelayoutpanel-is-displayed-with-large-empty-spaces-in-a-windows-forms-application-on-high-dpi-monitors) - better make sure you don't nest those table layout panels. – Roman Starkov May 02 '17 at 20:27
  • How to ignore text zoom in windows for win forms because this solution requires too much work (hundreds of forms)? – Hrvoje Batrnek Dec 18 '20 at 13:57
  • Forced to use a table layout panel? How about we want SplitContainers? – Dan W Oct 04 '21 at 01:35
  • Doesn't work anymore in 2023 :( – Daniel Jan 18 '23 at 09:55