Old 11-13-2013, 09:04 AM   #1
Lawrence
Human being with feelings
 
Join Date: Mar 2007
Posts: 21,551
Default Karbo: Mentoring Pants Tug

Karbo, my good friend and coding mentor.

I've exhausted all my options and I cannot figure out how to make my .NET apps scale correctly when the users Win OS is changed to scale 120 DPI, big fonts, whatever, in Win 7 or 8. It's driving me a little wacky. Any pointers would be appreciated. The few things I've tried don't seem to work.

My only other option - which I'm not looking forward to - is arranging the controls two completely different ways and parsing the scaling on launch to make sure everything is where it should be. Obviously, that would be a good bit of work that I would not want to do and I know there has to be a less fatiguing solution.

As it stands now, I'm telling users "Don't do that." Just don't set big scaling. But (obviously) that's not a good thing.

P.S. I would do this PM but for some odd reason my PM box is kinda screwy, never showing "Sent Items".
Lawrence is offline   Reply With Quote
Old 11-13-2013, 09:19 AM   #2
karbomusic
Human being with feelings
 
karbomusic's Avatar
 
Join Date: May 2009
Posts: 29,260
Default

Have you tried setting the AutoScaleMode to AutoScaleMode.Dpi for each control you care about?

I "think" that is supposed to handle what you need but don't quote me until you try it. I'm assuming that means that property only exists on controls that can contain other controls. In your case that would be the actual Windows Form control where you would set it to Dpi. IOW set it on the container (Form1) and any controls it contains should scale according to the system Dpi setting...

http://msdn.microsoft.com/en-us/libr...v=vs.110).aspx

Quote:
The ContainerControl class and classes derived from it, such as Form, can automatically resize themselves and their contents according to either the current system font or the resolution of the display, measured in dots per inch (DPI). The AutoScaleMode enumeration defines the automatic scaling modes supported by these classes and their derived types. A control's current mode can be accessed through its ContainerControl.AutoScaleMode property.

Most business applications should use the Font automatic scaling mode. The Dpi scaling mode is useful for graphics-based applications and is compatible with the default scaling used by the .NET Compact Framework.
Do ya remember the classic days when you had to write all any and all resize code yourself. Yuk!
__________________
Music is what feelings sound like.

Last edited by karbomusic; 11-13-2013 at 09:31 AM.
karbomusic is offline   Reply With Quote
Old 11-13-2013, 09:43 AM   #3
Lawrence
Human being with feelings
 
Join Date: Mar 2007
Posts: 21,551
Default

Yeah. This is the current code line I have on the form load sub, which doesn't seem to work.

Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi

I'll look and see if there are other containers on the form that can be addressed similarly, for the things on the form that are still scaling incorrectly.

Also, should I maybe put that line last in form load? Would it make any difference if that was set after all the controls were loaded?
Lawrence is offline   Reply With Quote
Old 11-13-2013, 10:10 AM   #4
karbomusic
Human being with feelings
 
karbomusic's Avatar
 
Join Date: May 2009
Posts: 29,260
Default

Quote:
Originally Posted by Lawrence View Post
Yeah. This is the current code line I have on the form load sub, which doesn't seem to work.

Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi

I'll look and see if there are other containers on the form that can be addressed similarly, for the things on the form that are still scaling incorrectly.

Also, should I maybe put that line last in form load? Would it make any difference if that was set after all the controls were loaded?
You might try putting it in InitializeComponent() or in the Contstructor of the Form class which calls InitializeComponent() which runs before Load() and is when much of the initialization of the form is done. I'm not sure how well it will work. Searching around a little it looks like you may need to set any child component containers to AutoScaleMode.None or .Inherit. I'm completely speculating without firing up an app and playing with it and be it may not be a clean solution using Win32 forms (which is what you are using right?).

Additionally, we are treading into territory that defines why WPF was created (to solve many of the issues with Win32 forms and graphics). IOW, WPF vastly handles scaling better but it's a slightly different animal to get used to. It's great where his type of thing is concerned but it's a curve on top of the existing .NET learning curve and as far in as you are it would be silly to start over in WPF just to handle scaling (I think).
__________________
Music is what feelings sound like.
karbomusic is offline   Reply With Quote
Old 11-13-2013, 10:39 AM   #5
Lawrence
Human being with feelings
 
Join Date: Mar 2007
Posts: 21,551
Default

I got it.

Here's the thing... I was placing controls manually x/y and when the scaling changed it all went to heck. So what I did was go back and re code those controls to position themselves relatively against the controls that actually did scale correctly.

This involved also not manually setting the grid column widths, but setting their widths relative to their headers (which are really buttons, that scale correctly).

Once I removed all of the manual sizing code it all worked out. Note to self, remember that.

Thanks man.
Lawrence is offline   Reply With Quote
Old 11-13-2013, 10:57 AM   #6
karbomusic
Human being with feelings
 
karbomusic's Avatar
 
Join Date: May 2009
Posts: 29,260
Default

Quote:
Originally Posted by Lawrence View Post
I got it.

Here's the thing... I was placing controls manually x/y and when the scaling changed it all went to heck. So what I did was go back and re code those controls to position themselves relatively against the controls that actually did scale correctly.

This involved also not manually setting the grid column widths, but setting their widths relative to their headers (which are really buttons, that scale correctly).

Once I removed all of the manual sizing code it all worked out. Note to self, remember that.

Thanks man.
Perfect and sweet! Can I assume you were using the wonderful "Anchor" property? That little fella is tremendously helpful for making controls "follow the form" in various ways.
__________________
Music is what feelings sound like.
karbomusic is offline   Reply With Quote
Old 11-13-2013, 11:12 AM   #7
Lawrence
Human being with feelings
 
Join Date: Mar 2007
Posts: 21,551
Default

Yeah, it took me a minute to wrap my brain around the obvious simple logic of all that.

If I placed a control manually X/Y and then the DPI resolution changes (duh) of course the relative X/Y position will change, relatively speaking. So technically, it was more a matter of "positioning" with the different DPI settings than the controls actually not scaling in size correctly.

Everything was scaling in "size" correctly, but they were not positioning themselves correctly on the DPI change... for obvious reasons... because I'd hard coded the positions at another DPI setting.

One of those real facepalm moments.

I mean... left 450 from the window border is here at one dpi...

|_______________________******

...but obviously somewhere else leftwards at a denser DPI setting...

|____________*******

It was still 450, but at a different place relative to the window it's inside of. (facepalm)

Thanks man. I hope you don't mind me calling on you when I get stuck on stuff like this. I'd hate to be a pest.

Last edited by Lawrence; 11-13-2013 at 11:22 AM.
Lawrence is offline   Reply With Quote
Old 11-13-2013, 11:23 AM   #8
karbomusic
Human being with feelings
 
karbomusic's Avatar
 
Join Date: May 2009
Posts: 29,260
Default

Quote:
Originally Posted by Lawrence View Post

Thanks man. I hope you don't mind me calling on you when I get stuck on stuff like this. I'd hate to be a pest.
Anytime, helping people out and sharing things I've had similar face palms over is actually a major part of my existence. AKA, its extremely fun and fulfilling. Now, I gotta run back to a colleagues desk and finish teaching him delgates and updating the GUI with another thread.
__________________
Music is what feelings sound like.
karbomusic is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 12:11 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.