EscribePassword/App.xaml.cs

59 lines
1.7 KiB
C#
Raw Normal View History

2024-06-15 06:24:07 -03:00
using System.Configuration;
using System.Data;
using System.Windows;
2024-06-15 14:33:52 -03:00
using Application = System.Windows.Application;
2024-06-15 06:24:07 -03:00
namespace EscribePassword
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
2024-06-15 14:33:52 -03:00
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;
}
}
2024-06-15 06:24:07 -03:00
}
}