博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
无边框窗体的拖动和拉伸
阅读量:7021 次
发布时间:2019-06-28

本文共 3796 字,大约阅读时间需要 12 分钟。

1 using System;  2 using System.Collections.Generic;  3 using System.ComponentModel;  4 using System.Data;  5 using System.Drawing;  6 using System.Linq;  7 using System.Text;  8 using System.Windows.Forms;  9 using System.Runtime.InteropServices; 10  11 namespace WindowsFormsApplication2 12 { 13     public partial class Form1 : Form 14     { 15         public Form1() 16         { 17             InitializeComponent(); 18             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; 19         } 20  21         protected override void OnMouseDown(MouseEventArgs e) 22         { 23             base.OnMouseDown(e); 24             if (e.Button == MouseButtons.Left && 25                 this.WindowState != FormWindowState.Maximized) 26             { 27                 ReleaseCapture(); 28                 SendMessage(this.Handle, 274, 61440 + 9, 0); 29             } 30         } 31  32         [DllImport("user32.dll")] 33         public static extern int ReleaseCapture(); 34  35         [DllImport("user32.dll")] 36         public static extern int SendMessage(IntPtr hwnd, int msg, int up, int lp); 37  38         protected override void WndProc(ref Message m) 39         { 40             switch (m.Msg) 41             { 42                 case (int)WindowsMessage.WM_NCHITTEST: 43                     this.WM_NCHITTEST(ref m); 44                     break; 45                 default: 46                     base.WndProc(ref m); 47                     break; 48             } 49         } 50  51         public static int LOWORD(int value) 52         { 53             return value & 0xFFFF; 54         } 55  56         public static int HIWORD(int value) 57         { 58             return value >> 16; 59         } 60  61         private void WM_NCHITTEST(ref Message m) 62         { 63             int wparam = m.LParam.ToInt32(); 64             Point point = new Point(LOWORD(wparam), HIWORD(wparam)); 65             point = this.PointToClient(point); 66  67             if (point.X <= 5) 68             { 69                 if (point.Y <= 5) 70                     m.Result = (IntPtr)WinAPIConst.HTTOPLEFT; 71                 else if (point.Y > this.Height - 5) 72                     m.Result = (IntPtr)WinAPIConst.HTBOTTOMLEFT; 73                 else 74                     m.Result = (IntPtr)WinAPIConst.HTLEFT; 75             } 76             else if (point.X >= this.Width - 5) 77             { 78                 if (point.Y <= 5) 79                     m.Result = (IntPtr)WinAPIConst.HTTOPRIGHT; 80                 else if (point.Y >= this.Height - 5) 81                     m.Result = (IntPtr)WinAPIConst.HTBOTTOMRIGHT; 82                 else 83                     m.Result = (IntPtr)WinAPIConst.HTRIGHT; 84             } 85             else if (point.Y <= 5) 86             { 87                 m.Result = (IntPtr)WinAPIConst.HTTOP; 88             } 89             else if (point.Y >= this.Height - 5) 90             { 91                 m.Result = (IntPtr)WinAPIConst.HTBOTTOM; 92             } 93             else 94                 base.WndProc(ref m); 95         } 96     } 97  98     public enum WindowsMessage 99     {100         /// 101         /// 移动鼠标,桉树或释放鼠标时发生102         /// 103         WM_NCHITTEST = 0x84,104     }105     public class WinAPIConst106     {107         public const int HTLEFT = 10;108         public const int HTRIGHT = 11;109         public const int HTTOP = 12;110         public const int HTTOPLEFT = 13;111         public const int HTTOPRIGHT = 14;112         public const int HTBOTTOM = 15;113         public const int HTBOTTOMLEFT = 0x10;//16114         public const int HTBOTTOMRIGHT = 17;115         public const int HTCAPTION = 2;116 117     }118 }

 

转载于:https://www.cnblogs.com/jeffqing/archive/2012/10/31/2748255.html

你可能感兴趣的文章
COBBLER无人值守安装
查看>>
解决golang.org/x包无法下载的问题
查看>>
ansible puppet saltstack三款自动化运维工具的对比
查看>>
PHP - windows下编译PHP 7.1的memcache
查看>>
手机互动网页项目总结(转)
查看>>
SAPCAR简单使用
查看>>
shell脚本每天自动备份mysql数据库
查看>>
TeamViewer 局域网 远程桌面
查看>>
Spring4学习笔记-Spring4整合Hibernate4
查看>>
linux下的文本dos格式转unix格式,去除^M符号
查看>>
bootstrap-面板--彩色面板
查看>>
Python成员运算符
查看>>
控件(1)spinner
查看>>
在浏览器地址键入URL,按下回车之后经历的流程
查看>>
IIS7 asp+access 提示 “数据库连接错误” 怎么解决
查看>>
Windows Server 2008 R2 NTP Server
查看>>
SQL Server 审核(Audit) -- 如何创建审核
查看>>
python脚本 读取配置文件cfg 不读#号和空行
查看>>
dojo1.8 培训教材 新手老手适用 - 汇丰银行 [英文]
查看>>
C# 方法的重载
查看>>