• WPF 窗口自定义拉伸


     .NET技术交流群 199281001 .欢迎加入。

     1   //自定义窗体拉伸
     2 
     3         public HwndSource _HwndkaifaSource;
     4         private const int WM_SYSCOMMAND = 0x112;
     5         [DllImport("user32.dll", CharSet = CharSet.Auto)]
     6         private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
     7 
     8         private Dictionary<ResizeDirection, Cursor> cursors = new Dictionary<ResizeDirection, Cursor>
     9         {
    10             {ResizeDirection.Top, Cursors.SizeNS},
    11             {ResizeDirection.Bottom, Cursors.SizeNS},
    12             {ResizeDirection.Left, Cursors.SizeWE},
    13             {ResizeDirection.Right, Cursors.SizeWE},
    14             {ResizeDirection.TopLeft, Cursors.SizeNWSE},
    15             {ResizeDirection.BottomRight, Cursors.SizeNWSE},
    16             {ResizeDirection.TopRight, Cursors.SizeNESW},
    17             {ResizeDirection.BottomLeft, Cursors.SizeNESW}
    18         };
    Register user32.dll
     1 public enum ResizeDirection
     2         {
     3             /// <summary>
     4             /// 5             /// </summary>
     6             Left = 1,
     7             /// <summary>
     8             /// 9             /// </summary>
    10             Right = 2,
    11             /// <summary>
    12             ///13             /// </summary>
    14             Top = 3,
    15             /// <summary>
    16             /// 左上
    17             /// </summary>
    18             TopLeft = 4,
    19             /// <summary>
    20             /// 右上
    21             /// </summary>
    22             TopRight = 5,
    23             /// <summary>
    24             ///25             /// </summary>
    26             Bottom = 6,
    27             /// <summary>
    28             /// 左下
    29             /// </summary>
    30             BottomLeft = 7,
    31             /// <summary>
    32             /// 右下
    33             /// </summary>
    34             BottomRight = 8,
    35         }
    ResizeDirection
     1         void Window_MouseMove(object sender, MouseEventArgs e)
     2         {
     3 
     4             if (Mouse.LeftButton != MouseButtonState.Pressed)
     5             {
     6                 FrameworkElement element = e.OriginalSource as FrameworkElement;
     7                 if (element != null && !element.Name.Contains("Resize")) this.Cursor = Cursors.Arrow;
     8             }
     9 
    10         }
    11 
    12         private void ResizePressed(object sender, MouseEventArgs e)
    13         {
    14 
    15             FrameworkElement element = sender as FrameworkElement;
    16             ResizeDirection direction = (ResizeDirection)Enum.Parse(typeof(ResizeDirection), element.Name.Replace("Resize", ""));
    17 
    18             this.Cursor = cursors[direction];
    19             if (e.LeftButton == MouseButtonState.Pressed) ResizeWindow(direction);
    20 
    21         }
    22 
    23         private void ResizeWindow(ResizeDirection direction)
    24         {
    25 
    26             SendMessage(_HwndkaifaSource.Handle, WM_SYSCOMMAND, (IntPtr)(61440 + direction), IntPtr.Zero);
    27 
    28         }
    Event
    1  this.SourceInitialized += delegate(object sender, EventArgs e)
    2  {
    3       this._HwndkaifaSource = PresentationSource.FromVisual((Visual)sender) as HwndSource;
    4 };
    5          this.MouseMove += new MouseEventHandler(Window_MouseMove);
    construction

    XAML 属性 :MouseMove="ResizePressed" MouseDown="ResizePressed"

  • 相关阅读:
    手写简易SpringMVC框架,包含@PathVariable
    高并发下,如何保证接口的幂等性?
    JAVA判断奇偶数
    多线程ForkJoin-分治思想
    websocket简单使用
    Git使用教程:最详细、最傻瓜、最浅显、真正手把手教!(转载学习)
    linux配置java环境变量(详细)
    java缓存技术的介绍(转载)
    java 多态性详解及常见面试题
    oracle数据库基础知识总结(一)
  • 原文地址:https://www.cnblogs.com/gaobing/p/yuxuaner.html
Copyright © 2020-2023  润新知