Deepak
Deepak

Reputation: 112

Setting the location of WPF window dynamically when we change the screen resolution from low to high

When we change screen resolution the WPF window not showing on proper location(Bottom Right).

1.Change screen resolution from high to lower value. 2.Open the WPF window. 3.Again change screen resolution from low to high.

The window will not display on proper location it is going Up . I want it to again at bottom right. How can I fix this problem?

Upvotes: 2

Views: 2202

Answers (1)

Vojtěch Dohnal
Vojtěch Dohnal

Reputation: 8104

You will have to move the window after resolution change using your own code I believe, something like this:

window.Left = SystemParameters.PrimaryScreenWidth - window.Width;
window.Top = = SystemParameters.PrimaryScreenHeight - window.Height;

Check this post to see, how to detect screen resolution change

http://social.msdn.microsoft.com/Forums/en-US/fc2f6dfa-f22c-477e-b3a5-54a088176932/detecting-screen-resolution-change

So the whole code would be like this:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;
    }

    void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
    {
        this.Left = SystemParameters.PrimaryScreenWidth - this.Width;
        this.Top = SystemParameters.PrimaryScreenHeight - this.Height;
    }
}

Upvotes: 2

Related Questions