0

I recently experienced a wierd behavior of a old VB.NET WinForm code. The code is working well and produce a correct design of my forms. I added a function to call an API. I added a new reference with my proxies to the code.

   If ApiHelper.Login(Username, Password) Then
       Application.Run(myForm)
   End If

Here is my API helper class:

Public Class ApiHelper

Public Shared Function Login(username As String, password As String) As Boolean
    DataProxies.SetToken()
    Dim _authService As IAuthenticationService = New AuthenticationService()
    Dim auth As Tuple(Of Boolean, User) = _authService.Login(username, password).Result
    If (auth.Item1) Then
        Dim user As User = auth.Item2
        Name = $"{user.FirstName} {user.LastName}"
        ApiInformations.ApiToken = user.SessionToken
    End If
    Return True
End Function
End Class

When I run myForm all my fonts are modified. some become bigger, some seems smaller. But this is maybe an effect of resolution change of my main form.

enter image description here

This is wierd because before using the API to login or id I simply bypass the login like this

   'If ApiHelper.Login(Username, Password) Then
       Application.Run(myForm)
   'End If

I get a perfect result with all correct size on my form.

enter image description here

How a code that use nothing related to design and form (but async await) can affect the designer of my form?

Also my settings are

enter image description here

Bastien Vandamme
  • 17,659
  • 30
  • 118
  • 200
  • 1
    Can you add screenshots to show "before and after" effect? Have you debugged to see if the controls/form have same font-size set in both scenarios? – Esko Mar 01 '19 at 06:30
  • The snippet is not a great lead, but the problem is common enough these days. Happens on recent Win10 versions when that code calls SetProcessDpiAware(). Previously that function had to be called before creating any windows, today it is instantly effective. If you can tweak that code then the only decent workaround is to stay ahead of it and make your app dpiAware yourself: https://stackoverflow.com/a/13228495/17034 – Hans Passant Mar 01 '19 at 06:46
  • If you can assume that this code uses WPF then [this can help](https://stackoverflow.com/a/32245857/17034). – Hans Passant Mar 01 '19 at 06:49
  • What I don't understand is why I get this scale issue only when I run code that access some await async code that call my API. Event if I load the library I get no issue when I comment this part of code. – Bastien Vandamme Mar 01 '19 at 06:53
  • It's not clear from the code snippet if you're are using (knowingly or not) 3rd party components/assemblies for that Login proc. If that is the case, you may be unwillingly triggering dpiAwareness because the 3rd party component or a dependency uses a WPF assembly. Beside what Hans Passant already said, look at this: [DPI Awareness - Unaware in one Release, System Aware in the Other](https://stackoverflow.com/a/50276714/7444103). – Jimi Mar 01 '19 at 14:12

0 Answers0