SAVE AND RESTORE TWO SCREEN POSITION

private string C_REG_ADR = "SOFTWARE\\COMPANY\\2017";

private void Window_Loaded(object sender, RoutedEventArgs e) {
    setWindowPositionFromRegistry(this, C_REG_ADR, "main");
}

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
  e.Cancel = false;
  writeWindowPosition2Registry(this, C_REG_ADR, "main");
}



// basis methods

        public void setWindowPositionFromRegistry(Window dialog, String regadr, String title) {
            // 1:  ein Bildschirm nur PrimaryScreenWidth/PrimaryScreenHeight
            // 2:  zwei Bildschirme  VirtualScreenWidth  0 bis Width(1)+Width(2)
            // 3:  zwei Bildschirme  VirtualScreenWidth mit 0 bis Width(1)+Width(2)
            //             width ist aber   -Width(2) bis Width(1)
            int iTop = Basis.ReadRegInt(regadr, title + "_Top1");
            int iLeft = Basis.ReadRegInt(regadr, title + "_Left1");
            int iWidth = Basis.ReadRegInt(regadr, title + "_Width1");
            int iHeight = Basis.ReadRegInt(regadr, title + "_Height1");
            int w = (int)System.Windows.SystemParameters.PrimaryScreenWidth;
            int h = (int)System.Windows.SystemParameters.PrimaryScreenHeight;

            int virtualLeft = (int)System.Windows.SystemParameters.VirtualScreenLeft;
            int virtualW = (int)System.Windows.SystemParameters.VirtualScreenWidth;  // beide Breiten zusammen positiv
            int virtualH = (int)System.Windows.SystemParameters.VirtualScreenHeight;
            // iLeft kann negativ sein   und zwar  -SecondWidth
            if (iTop > 0 && (iTop - (iHeight >> 1) <= virtualH) && (iLeft >= virtualLeft) && iWidth > 50) {
                dialog.Top = iTop;
                dialog.Left = iLeft;
                dialog.Width = iWidth;
                dialog.Height = iHeight;
            }
            else {
                dialog.Top = 100;
                dialog.Left = 20;
            }
        }  // setWindowPositionFromRegistry

        public void writeWindowPosition2Registry(Window dialog, String regadr, String title) {
            Basis.WriteRegInt(regadr, title + "_Top1", (int)dialog.Top);
            Basis.WriteRegInt(regadr, title + "_Left1", (int)dialog.Left);
            Basis.WriteRegInt(regadr, title + "_Width1", (int)dialog.Width);
            Basis.WriteRegInt(regadr, title + "_Height1", (int)dialog.Height);
        }  // writeWindowPosition2Registry




ContextMenu