WPF自定义最大化及还原按钮,支持双击标题栏空白处的最大化及还原处理...

WPF自定义最大化及还原按钮,支持双击标题栏空白处的最大化及还原处理...

2023年7月19日发(作者:)

WPF⾃定义最⼤化及还原按钮,⽀持双击标题栏空⽩处的最⼤化及还原处理代码:

代码:

StateChanged="Window_StateChanged">

代码:using System;using c;using ;using ;using ;using s;using ls;using ;using nts;using ;using ;using g;using tion;using ;namespace WpfToolbar{ ///

/// 的交互逻辑 /// public partial class MainWindow : Window public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); dowFullScrreng(this); } private void bdMin_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { State = zed; } bool isExcuted = false;//点击最⼤化按钮时,阻⽌被StateChanged事件再次调⽤ private void bdMax_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { isExcuted = true; if (State == ) { = new BitmapImage(new Uri("Image/", ve)); State = zed; } else { = new BitmapImage(new Uri("Image/", ve)); State = ; } isExcuted = false; }

private void bdClose_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) {

();

}

private void Window_StateChanged(object sender, EventArgs e) { if (!isExcuted) { if (State == ) { = new BitmapImage(new Uri("Image/", ve)); State = ; } else if (State == zed) { = new BitmapImage(new Uri("Image/", ve)); State = zed; } } } }}

WindowsFullScreenHelper类代码:using System;using c;using ;using pServices;using ;using s;using p;namespace WpfToolbar{ public class WindowsFullScreenHelper { private static Window movewin; public static void SetWindowFullScrreng(Window wpfWindow) { movewin = wpfWindow; if (wpfWindow == null) { return; } if (State == zed) { State = ; += delegate { State = zed; }; } Initialized += delegate { IntPtr handle = (new WindowInteropHelper(wpfWindow)).Handle; HwndSource source = nd(handle); if (source != null) { k(WindowProc); } }; } private static IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { switch (msg) { case 0x0024: WmGetMinMaxInfo(hwnd, lParam); // handled = true; break; } return (IntPtr)0; } private static void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam) { var mmi = (MINMAXINFO)tructure(lParam, typeof(MINMAXINFO)); // Adjust the maximized size and position to fit the work area of the correct monitor int MONITOR_DEFAULTTONEAREST = 0x00000002; IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); if (monitor != ) { var monitorInfo = new MONITORINFO(); GetMonitorInfo(monitor, monitorInfo); RECT rcWorkArea = ; RECT rcMonitorArea = tor; osition.x = ( - ); osition.y = ( - ); ize.x = ( - ); ize.y = ( - ); } ureToPtr(mmi, lParam, true); } [DllImport("user32")] internal static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi); ///

/// ///

///

[DllImport("User32")] internal static extern IntPtr MonitorFromWindow(IntPtr handle, int flags); #region Nested type: MINMAXINFO [StructLayout(tial)] internal struct MINMAXINFO { public POINT ptReserved; public POINT ptMaxSize; public POINT ptMaxPosition; public POINT ptMinTrackSize; public POINT ptMaxTrackSize; }; #endregion #region Nested type: MONITORINFO /// /// [StructLayout(tial, CharSet = )] internal class MONITORINFO { /// ///

public int cbSize = (typeof(MONITORINFO)); ///

///

public RECT rcMonitor; ///

///

public RECT rcWork; ///

///

public int dwFlags; } #endregion #region Nested type: POINT ///

/// POINT aka POINTAPI /// [StructLayout(tial)] internal struct POINT { /// /// x coordinate of point. /// public int x; /// /// y coordinate of point. /// public int y; /// /// Construct a point of coordinates (x,y). /// Construct a point of coordinates (x,y). /// public POINT(int x, int y) { this.x = x; this.y = y; } } #endregion #region Nested type: RECT /// Win32 [StructLayout(tial, Pack = 0)] internal struct RECT { /// Win32 public int left; /// Win32 public int top; /// Win32 public int right; /// Win32 public int bottom; /// Win32 public static readonly RECT Empty; /// Win32 public int Width { get { return (right - left); } // Abs needed for BIDI OS } /// Win32 public int Height { get { return bottom - top; } } /// Win32 public RECT(int left, int top, int right, int bottom) { = left; = top; = right; = bottom; } /// Win32 public RECT(RECT rcSrc) { left = ; top = ; right = ; bottom = ; } /// Win32 public bool IsEmpty { { get { // BUGBUG : On Bidi OS (hebrew arabic) left > right return left >= right || top >= bottom; } } /// Return a user friendly representation of this struct public override string ToString() { if (this == Empty) { return "RECT {Empty}"; } return "RECT { left : " + left + " / top : " + top + " / right : " + right + " / bottom : " + bottom + " }"; } /// Determine if 2 RECT are equal (deep compare) public override bool Equals(object obj) { if (!(obj is )) { return false; } return (this == (RECT)obj); } /// Return the HashCode for this struct (not garanteed to be unique) public override int GetHashCode() { return hCode() + hCode() + hCode() + hCode(); } /// Determine if 2 RECT are equal (deep compare) public static bool operator ==(RECT rect1, RECT rect2) { return ( == && == && == && == ); } /// Determine if 2 RECT are different(deep compare) public static bool operator !=(RECT rect1, RECT rect2) { return !(rect1 == rect2); } } #endregion }}

发布者:admin,转转请注明出处:http://www.yc00.com/xiaochengxu/1689717706a280652.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信