2

Okay, after an hour of search, I hope asking myself will give me some answer.
Basically, I want to write a tiny program that can swap my desktop resolution between 1920x1080 and 1280x800 automatically by running a simple script.

I started with:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        this.Loaded += SwapResol;
    }

    private void SwapResol(object sender, EventArgs e)
    {
        double width = System.Windows.SystemParameters.PrimaryScreenWidth;
        if(width == 1920)
        {
            //set it to 1280x800
        }
        if(width == 1280)
        {
            //set it to 1920x1080
        }

        this.Close();
    }
}

When I realized that System.Windows.SystemParameters.PrimaryScreenWidth (and height) both only have getters implemented.
If I run any script as an admin, is there a way to change the resolution in code? I have found tons of questions about getting the resolution and using it for the program but nothing on setting it.
Does Windows even allow changing it some other way than using the 'standard method'?

This question already exists, but the suggested answer seems to refer solving the problem in C++ by not using .NET.

Community
  • 1
  • 1
philkark
  • 2,417
  • 7
  • 38
  • 59

0 Answers0