1

My Winforms application appears very blurry when executed without a manifest file. With it and the added code

<System.Windows.Forms.ApplicationConfigurationSection>
    <add key="DpiAwareness" value="PerMonitorV2" />
</System.Windows.Forms.ApplicationConfigurationSection>

the blurriness does disappear, but it requires the user to have an additional .config file to make the app look crisp when running it. I have tried setting the AutoScaleMode variable of my form to Font and Dpi, neither made a difference. I have also found online the SetProcessDpiAwarenessContext function, but I'm unsure if this is what I'm looking for and I do not know how to implement it into my code.

Is it possible to remove the blurriness from my app without a manifest file at all?

Ero
  • 69
  • 7
  • Does this answer your question? [DPI Awareness - Unaware in one Release, System Aware in the Other](https://stackoverflow.com/questions/50239138/dpi-awareness-unaware-in-one-release-system-aware-in-the-other) – pinkfloydx33 Jul 24 '20 at 23:22
  • Also this, https://stackoverflow.com/q/43537990/491907 though read Jimi's answer to the first link I posted. The values passed to the function are apparently not a true enum but contextual, meaning you have to call Get and use its result to call Set (Apparently the enums defined on this link aren't exactly correct) – pinkfloydx33 Jul 24 '20 at 23:24
  • I'm unsure. I have a hard time discerning what is relevant information in that topic and what I am able to do with it. – Ero Jul 24 '20 at 23:26
  • Follow the bottom of Jimi's answer. Call GetProcessDpiAwarenessContext and use its result to then call SetProcessDpiAwarenessContext all at the very start of your application before any other line of code. Aside: that in fact does answer your question, I wasn't suggesting that it *might*. That's the canned stack overflow text for marking a duplicate – pinkfloydx33 Jul 24 '20 at 23:28
  • I should mention that I'm very much a beginner and am very unsure how to implement this into my code; which file it goes into, which lines I exactly have to add. I know asking to be spoonfed is frowned upon, but I need a bit of clarification and help. – Ero Jul 24 '20 at 23:29
  • Then follow the other link (albeit, cross your fingers since jimi says it shouldn't work but others have suggested it does) – pinkfloydx33 Jul 24 '20 at 23:31
  • Hm, it seems I'm unable to follow those steps. My project does not have a `App.xaml`, as it's not a WPF project, but a Winforms one. – Ero Jul 24 '20 at 23:44
  • I have used Jimi's solution now. I inserted the code at the start of my `Program.cs`. I'm getting a few errors now though. They're all CS0246. They occur at the use of `InPtr` (is this a typo?) and every use of `DPI_AWARENESS_CONTEXT` in the enum. What's going on? – Ero Jul 25 '20 at 00:36
  • Hey I don't actually know anything about this. I was just looking to check if this was a duplicate question. If you read Jimi's instructions he notes that it's not a real enum (nor can it be) and that the example is meant to highlight what it *would* look like if it were one. That said, I think you can adapt it by using the examples in the second link I posted. – pinkfloydx33 Jul 25 '20 at 10:46
  • .net core 3.x/5 has [Application.SetHighDpiMode(HighDpiMode) Method](https://github.com/dotnet/winforms/commit/72f3ec6a14c7093e4694f8474abb8fdae2d3b33d#diff-4173f7393ee6c4f434e5c5dfebd0ff3cR362) to do this. – magicandre1981 Jul 26 '20 at 12:40

0 Answers0