VB.NET2010 and New Display Text options in Windows 7+

Hi Guys,

We have developed and distributed our software to many customer, and since Windows 7, Microsoft have introduced the 100%, 125%, 150% option in Control Panel and Display.

This causes buttons to appear behind panels, text to appear misaligned in Buttons etc. when set to 125%+.

Does anyone have any recommendations in how to deal with this, as it's giving our software a very bad impression with our customers, when it's not our fault!

We are using Visual Studio 2010 and VB.NET
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
What type of application are you using?
KBannerAuthor Commented:
Hi TheLearnedOne,

Thanks for posting!

The Windows OS is Windows 7!
We are using a product called TrackerPro developed on Visual Studio 2010 in VB.NET

Have seen a couple of references to AutoScaleMode and AutoSize.

When I change my development PC to 125% or 150%, the Texts and Image skewed as they do when we run the exe with Display setting on 125%
Bob LearnedCommented:
That sounds like a Windows Forms application, and while I have a lot of experience with Windows Forms, I have moved on to WPF applications, as they handle this type of change much better.

You need to come up with the same dynamic layout that WPF has, where objects can move.  That gets to be tricky when trying to get the right layout.  I have found that the TableLayoutPanel can come in handy when trying to get percentage-based layout, but can be cumbersome for complex requirements.
KBannerAuthor Commented:
Arhh OK, what a pain microsoft are!!! What about ensuring that the users PC is on 100% dynamically by setting it in the code. Would this be possible, as this is impacting our overall impression of our product!

Would you know how to do that theLearnedOne?
Bob LearnedCommented:
Also, as a web developer, I don't do much desktop development, but you might find an answer here:

How to maintain the default font size of Windows Forms application even after the entire Windows Text size is changed from Small to Medium?

Public Class FontResizeFactorProvider
	Private Const DpiSmallSize As Integer = 96
	Private Const DpiMediumSize As Integer = 120
	Private Const DpiLargeSize As Integer = 144

	Public Function GetFontResizeFactor() As Single
		Dim graphics__1 = Graphics.FromHwnd(IntPtr.Zero)
		Dim desktop As IntPtr = graphics__1.GetHdc()

		Dim displayDimensions = New List(Of Integer)() From { _
			GetDeviceCaps(desktop, CInt(DeviceCap.LOGPIXELSX)), _
			GetDeviceCaps(desktop, CInt(DeviceCap.LOGPIXELSY)) _

		Dim matchedDim = displayDimensions.First(Function([dim]) [dim] = DpiSmallSize OrElse [dim] = DpiMediumSize OrElse [dim] = DpiLargeSize)

		If matchedDim = 0 Then
			Throw New ArgumentException("Dpi size not standard.")
		End If

		Dim resizeFactor = CSng(DpiSmallSize) / matchedDim

		Return resizeFactor
	End Function

	Public Declare Auto Function GetDeviceCaps Lib "gdi32.dll" (hDC As IntPtr, nIndex As Integer) As Integer

	Public Enum DeviceCap
		''' <summary>
		''' Logical pixels inch in X
		''' </summary>
		''' <summary>
		''' Logical pixels inch in Y
		''' </summary>

		' Other constants may be founded on pinvoke.net
	End Enum
End Class

Open in new window

Public Class FormFontsResizeService
	Private Const EPSILON As Double = 0.1
	Private ReadOnly _fontResizeFactorProvider As FontResizeFactorProvider

	Public Sub New()
		Me.New(New FontResizeFactorProvider())
	End Sub

	Public Sub New(fontResizeFactorProvider As FontResizeFactorProvider)
		_fontResizeFactorProvider = fontResizeFactorProvider
	End Sub

	Public Sub ResizeControlFonts(form As Form)
		Dim resizeFactor = _fontResizeFactorProvider.GetFontResizeFactor()

		For Each control As Control In form.Controls
			Dim baseFont = control.Font

			If Math.Abs(baseFont.Size - SystemFonts.DefaultFont.Size) < EPSILON Then
				Continue For
			End If

			Dim scaledFont = New Font(baseFont.FontFamily, baseFont.Size * resizeFactor, baseFont.Style)
			control.Font = scaledFont
	End Sub
End Class

Open in new window

Protected Overrides Sub OnShown(e As System.EventArgs)
	Dim formFontsResizeService = New FormFontsResizeService()
End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.