zoukankan      html  css  js  c++  java
  • 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"

  • 相关阅读:
    神经网络和深度学习之——前馈神经网络
    神经网络和深度学习之感知器工作原理
    神经网络和深度学习之神经元和感知器
    基于keras的BiLstm与CRF实现命名实体标注
    基于双向BiLstm神经网络的中文分词详解及源码
    Net Core中数据库事务隔离详解——以Dapper和Mysql为例
    利用卷积神经网络(VGG19)实现火灾分类(附tensorflow代码及训练集)
    AlexNet 网络详解及Tensorflow实现源码
    ASP.NET Core MVC I/O编程模型
    Tensorflow开发环境配置及其基本概念
  • 原文地址:https://www.cnblogs.com/gaobing/p/yuxuaner.html
Copyright © 2011-2022 走看看