1

I am trying to figure out how to get the user's monitor resolution on all desktop platforms (Windows, OSX, Linux), but all solutions I can find on the Internet are not cross-platform. They all use references to Windows Forms and WPF, both of which are Windows-only. Does anyone know how to get the monitor resolution?

  • Unfortunately there isn't a unified way to tell screens and their resolutions on different operating systems, so you are supposed to consume different APIs on them. Frameworks such as Avalonia might have some common methods for such but if you don't use them it's a big burden to take dependencies. – Lex Li Dec 28 '21 at 04:08
  • 2
    @MickyD WinForms and WPF are both Windows-only, even in .NET 6. – Wannabe Programmer Dec 28 '21 at 04:39
  • I'm pretty sure that you're not going to be able to do this natively in .NET Core / 6. Any solutions that I can find that don't reference the aforementioned libraries just end up importing DLLs and calling Win32 APIs directly. – jhmckimm Dec 28 '21 at 04:42
  • The best idea that I can come up with is using a wrapper for cross-platform graphics libraries and seeing if there are any utilities that will give you what you're looking for. – jhmckimm Dec 28 '21 at 04:44
  • @WannabeProgrammer darn. Well that's confusing. If that's the case I wonder why they didn't keep all the other goodies. _I learnt something new today_ –  Dec 28 '21 at 05:20
  • The best solution I can think of is to PInvoke for each platform, but I am only familiar with Windows. Do you guys know how I would do this in OSX/Linux? – Wannabe Programmer Dec 28 '21 at 15:20
  • for MacOS I used `NSScreen` (https://developer.apple.com/documentation/appkit/nsscreen). See sample here https://stackoverflow.com/a/16634349/2011071 – Serg Dec 28 '21 at 16:41

0 Answers0