Files
C4IT-F4SD-Client/F4SD_IconPicker/F4SDicons/User Controls/WindowStateBar.xaml.cs
2025-11-11 11:03:42 +01:00

167 lines
4.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace F4SDicons.User_Controls
{
public partial class WindowStateBar : UserControl
{
public WindowStateBar()
{
InitializeComponent();
}
public bool isWindowRight = false;
#region DockWindow
//TopLeft Position of Screen
public static void TopLeftCorner(System.Windows.Window window)
{
var screen = System.Windows.Forms.Screen.FromPoint(new System.Drawing.Point((int)window.Left, (int)window.Top));
window.Top = screen.WorkingArea.Top;
window.Left = screen.WorkingArea.Left;
}
//TopRight Position of Screen
public static void TopRightCorner(System.Windows.Window window)
{
var screen = System.Windows.Forms.Screen.FromPoint(new System.Drawing.Point((int)window.Left, (int)window.Top));
window.Top = screen.WorkingArea.Top;
window.Left = screen.WorkingArea.Left + window.ActualWidth + window.ActualWidth;
}
public static void TopRightCorner2(System.Windows.Window window)
{
var screen = System.Windows.Forms.Screen.FromPoint(new System.Drawing.Point((int)window.Left, (int)window.Top));
window.Top = screen.WorkingArea.Top;
window.Left = screen.WorkingArea.Right - window.ActualWidth;
}
private void WindowToTopLeftCorner(object sender, MouseButtonEventArgs e)
{
resizeWindow();
TopLeftCorner(Window.GetWindow(this));
isWindowRight = false;
}
private void WindowToTopRightCorner(object sender, MouseButtonEventArgs e)
{
resizeWindow();
TopLeftCorner(Window.GetWindow(this));
isWindowRight = false;
TopRightCorner(Window.GetWindow(this));
isWindowRight = true;
}
#endregion
#region Minimize
//Minimize Window
private void minimizeWindow_ButtonUp(object sender, MouseButtonEventArgs e)
{
Window.GetWindow(this).WindowState = WindowState.Minimized;
}
#endregion
#region Resize
//Resize Window
private void resizeWindow2_ButtonUp(object sender, MouseButtonEventArgs e)
{
resizeWindow2();
if (isWindowRight == false)
{
TopLeftCorner(Window.GetWindow(this));
}
else
{
TopRightCorner2(Window.GetWindow(this));
}
resizeIcon.Visibility = Visibility.Visible;
resizeIcon2.Visibility = Visibility.Collapsed;
}
private void resizeWindow()
{
Rect rectangle = GetCurrentScreenWorkArea(Window.GetWindow(this));
double wHeight = rectangle.Height;
double wWidth = rectangle.Width;
wWidth = wWidth / 3;
Window.GetWindow(this).Height = wHeight;
Window.GetWindow(this).Width = wWidth;
resizeIcon2.Visibility = Visibility.Visible;
resizeIcon.Visibility = Visibility.Collapsed;
}
private void resizeWindow2()
{
Window.GetWindow(this).Height = 600;
Window.GetWindow(this).Width = 880;
}
#endregion
#region Display
public static Rect GetCurrentScreenWorkArea(System.Windows.Window window)
{
var screen = System.Windows.Forms.Screen.FromPoint(new System.Drawing.Point((int)window.Left, (int)window.Top));
var dpiScale = VisualTreeHelper.GetDpi(window);
return new Rect { Width = screen.WorkingArea.Width / dpiScale.DpiScaleX, Height = screen.WorkingArea.Height / dpiScale.DpiScaleY };
}
#endregion
#region Close Window
private void closeWindow_ButtonUp(object sender, MouseButtonEventArgs e)
{
Window.GetWindow(this).Close();
}
#endregion
#region Drag Move
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Window.GetWindow(this).DragMove();
}
#endregion
}
}