using System.Configuration; using System.Data; using System.Windows; using Application = System.Windows.Application; namespace EscribePassword { /// /// Interaction logic for App.xaml /// public partial class App : Application { public KeyboardHelper PasteLogic { get; } = new KeyboardHelper(); protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); PasteLogic.SaveCurrentWindow(); SetInitialWindowPosition(); } public void SetInitialWindowPosition() { var screenRect = PasteLogic.GetScreenOfPreviousWindow(); var mainWindow = Application.Current.MainWindow; if (mainWindow != null) { // Obtener la posición del cursor var cursorPosition = System.Windows.Forms.Cursor.Position; // Determinar en qué pantalla está el cursor var screen = Screen.FromPoint(cursorPosition); // Determinar la posición inicial double newLeft = screenRect.Right; double newTop = screenRect.Top; // Verificar si la ventana se posiciona fuera de la pantalla y ajustarla si es necesario if (newLeft < screenRect.Left) { newLeft = screenRect.Left; } if (newLeft + mainWindow.Width > screen.WorkingArea.Right) { newLeft = screen.WorkingArea.Right - mainWindow.Width; } // Aplicar la nueva posición mainWindow.Left = newLeft; mainWindow.Top = newTop; } } } }