?
Solved

Resize of Form based on Font size in VB.NET

Posted on 2005-03-03
8
Medium Priority
?
4,623 Views
Last Modified: 2013-12-03
What is the best way to set the form size dynamically at initialization time based on the DPI to text size? Any ideas?

I have a form that is NOT re-sizable. It is a fixed form. But I need it to size dynamically based on the DPI settings.

In other words, if I was to change the desktop to 1280 x 1024 and the DPI settings to 120, my form should resize accordingly based on that information.

Any solutions?
0
Comment
Question by:cjinsocal581
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 2

Assisted Solution

by:lordicarus
lordicarus earned 1000 total points
ID: 13452424
in your load event you will want something along these lines...

[code]
        Me.Width = Screen.PrimaryScreen.WorkingArea.Width * 0.7
        Me.Height = Screen.PrimaryScreen.WorkingArea.Height * 0.5
        Dim g As Graphics = Me.CreateGraphics
        For Each mCtrl As Control In Me.Controls
            Dim mFnt As Font = mCtrl.Font
            mCtrl.Font = New Font(mFnt.FontFamily, sizeFormula)
        Next
[/code]

I'm still trying to find out what "sizeFormula" would be... I'm not sure exactly how to convert a pixel font size to an em font size, but thats the basic idea.
0
 
LVL 7

Accepted Solution

by:
Joe_Griffith earned 1000 total points
ID: 13453927
If you have the form's AutoScale property set to true then the form should automatically change size.

This doesn't work if you are explicitly setting the size in your code.
0
 
LVL 6

Author Comment

by:cjinsocal581
ID: 13453951
Perfect.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:lordicarus
ID: 13454090
On my computer even with that on, it doesnt scale the form to display properly in different resolutions... it scales along with the resolution and gets bigger when i make my resolution smaller... what i mean by that is bringing my resolution from 1280x1024 to 800x600, the size of my test form remains 300 by 300, when the way I thought this question was to be interpreted was that in 1280x1024 the size should be 300 by 300 but in 800 by 600 it should be 187.5 by 175.78125(the same screen to form size ratio), and the fonts should also appropriately scale.  With Autoscale turned both on or off, this is not the behavior of my form.  Is this what you are saying happens Joe or am I misinterpreting you.
0
 
LVL 2

Expert Comment

by:lordicarus
ID: 13454122
A little further investigation seems that this only changes if you goto the Display settings in windows, goto the appearance tab, and change the font size from normal to extra large... at least this is what the documentation tells me... because this doesnt happen either.
0
 
LVL 7

Expert Comment

by:Joe_Griffith
ID: 13454164
The screen resolution is not the issue.  If you change the resolution the form will appear bigger or smaller but it will still have the same size in pixels.

What causes the problem is changing the DPI setting (Display Properties, Advanced, General).

Most systems are set at 96DPI.  AutoScale will accomodate most other settings (120 is the one some people use) by changing the size of the form (although the change isn't perfect).  What doesn't work is if you explicitly set the size of the form in pixels in your code.  The autoscale feature then doesn't work and, typically going from 96 to 120 will result in part of the form being chopped off.
0
 
LVL 2

Expert Comment

by:lordicarus
ID: 13454830
I see what you are saying, but part of the changing the form size explicitly in code, you can use

Dim g As Graphics = Me.CreateGraphics
g.DpiX

where g.DpiX is the dpi setting of the monitor.  With this value you can create that formula to automatically handle the DPI, but at the same time, you have to take into account the fact that that DPI isnt truly dots per inch.  True dots per inch is calculating how many pixels are on your screen and dividing it by the visible size of the screen in inches.  Using the AutoScale property only handles the "virtual" dpi.  You have to take into account true dpi as well.  Based on the way the question was asked I thought the solution needed was for the true dpi.  I agree with you completely, I think I just lost something in my interpretation of the question.
0
 

Expert Comment

by:Aloha_Technology
ID: 21438352
hi,
can anybody have a sample code to locate form based on the true dpi?
please provides it urgently if possible.

thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question