• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 830
  • Last Modified:

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
  • 3
  • 2
1 Solution
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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now