3

Basically, I want everything (Controls etc) to scale with the WindowsForm when resizing it by dragging, so that the user can determine the size of the UI himself. The picture is not perfect, but I hope it explains it:

Resize approximation

The easiest way to do this would be to use a (Flow/Table)LayoutPanel and the appropriate Anchor/Drop properties, but I feel like that restricts my design, which currently looks like this:

My Design

My idea was to scale all the components when Resize() is called:

foreach(Control c in Controls){
            c.Scale(scaleFactor);
        }

My problems are: Locations aren't set properly and the rounding needed to determine the 'scaleFactor' leads to inconsistencies.

Is there a clean way to do all this? Do I have to use LayoutPanels to get a clean way?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
knallfrosch
  • 387
  • 6
  • 16
  • 1
    Not sure if you want to rewrite everything but WPF arguably makes this sort of thing easier –  Nov 25 '15 at 08:16
  • We're only 2 programmers, the program is used by engineers (doesn't have to be pretty) and using the visual designer is quite nice. Right now, we only have the UI, but I fear that learning and writing WPF is slower. – knallfrosch Nov 25 '15 at 08:43
  • Perhaps, though it may be a question of what is possible vs what isn't. WinForms won't scale fonts easily whereas WPF will. Everything in WPF is a _transform_. In WinForms you could render everything to an offscreen image; blow it up; and render it. Though it would be static so not sure how useful that is sadly. :( –  Nov 25 '15 at 08:49
  • You are doing this backwards. Why would the user *want* to change the size of the window? Not to make the text more readable, having a visual impairment applies to any program and the user will simply increase the DPI, nothing you have to do. Only possible reason that I could see from your UI design is to make more space available in the text boxes. That's very trivial to implement, just use the right anchor. All that's left to do is ensure it is still usable when he makes the window *smaller*, trivial too with MinimumSize and AutoScroll. – Hans Passant Nov 25 '15 at 10:10
  • It would provide the user with a _consistent_ UI, e.g. one that changes no proportions, while the user is able to allocate as much screen area as he sees fit. However; seeing how there is no good solution to my approach and seeing the advantages of other ways, I'll create the UI with layouts. – knallfrosch Nov 25 '15 at 10:28

2 Answers2

1

Are you sure that you want to zoom those text boxes and labels, too? Text boxes have a fairly standard height, for example. What do you expect if the window is so small that the text is too large for the buttons/text boxes, etc.?

The typical resizing logic of the contents of a resizable window is a little bit different. I would rather create a borderless panel for the groupboxes and stack/dock everything like this:

before resize

If I resize this window, that will look like this:

after resize

Btw, I do not like if buttons are resized like this. I would use only Anchor = Left, Right for them so they would preserve their height. And do not forget to set a proper MinimumSize for the form.

György Kőszeg
  • 17,093
  • 6
  • 37
  • 65
-1

Simplest and cleanest way is use layout panles.
It's hard to code location of controls which depends of previous control's location and size (expect case when you know order of controls).

In WPF everything are on ContentControl which is layout panel. Location of control is calculated automatically.

Another problem might be scaling font or glyph icon in combobox. In WPF this simplest and supported.

siwydym67
  • 129
  • 4
  • 12