Search code examples
c#winformsfontshighdpiphotoviewer

WinForms app spawning Windows Photo Viewer affect fonts in original app


We have a WinForms desktop application running on Windows 7 with the desktop set to 150% font size. We use Process.Start() to launch a viewer to display documents stored in our database. When a photo is viewed, Windows Photo Viewer is launched. When this occurs, many of the fonts in the application are changed. The menu fonts are particularly affected. I assume that this is related, somehow to the high DPI handling in the WinForms library. However, I'm surprised that launching Windows Photo Viewer would cause a change to the desktop that would affect the application. Settings of 125% or 175% do not have this effect.

Is there some way to insulate our application, once running from being affected this way?


Solution

  • Like you, our application stores files in our database. When the users need to view a file, the program retrieves it from the database and saves it to the local drive. Once saved, it then opens the file by using a ShellExecute call.

    I have been experiencing this same issue with jpgs set to open in Windows Photo Viewer when fonts are set to greater than 100% in Windows 7. In my tests, this ONLY affects the calling application. The application is not affected when opening the same jpg from Windows Explorer or Start | Run.

    Based on that and after spending many hours looking for a solution, I finally settled on this "hack" to work around the problem. I created a separate EXE that ONLY opens the file passed in as a parameter. I then changed my main application from opening the JPG to launching this new EXE with the jpg file location as the parameter. Now the new EXE is the "original app" instead of my main app, so my main app is not affected.