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

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

 

 

Frm_Main.cs

View Code
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 DragNoFrameForm 12 {
13 public partial class Frm_Main : Form 14 {
15 public Frm_Main() 16 {
17 InitializeComponent(); 18 } 19 20 #region 本程序中用到的API函数 21 [DllImport("user32.dll")] 22 public static extern bool ReleaseCapture();//用来释放被当前线程中某个窗口捕获的光标 23 [DllImport("user32.dll")] 24 public static extern bool SendMessage(IntPtr hwdn,int wMsg,int mParam,int lParam);//向指定的窗体发送Windows消息 25 #endregion 26 27 #region 本程序中需要声明的变量 28 public const int WM_SYSCOMMAND = 0x0112;//该变量表示将向Windows发送的消息类型 29 public const int SC_MOVE = 0xF010;//该变量表示发送消息的附加消息 30 public const int HTCAPTION = 0x0002;//该变量表示发送消息的附加消息 31 #endregion 32 33 private void ExitContext_Click(object sender, EventArgs e) 34 {
35 Application.Exit();//退出本程序 36 } 37 38 private void Frm_Main_MouseDown(object sender, MouseEventArgs e) 39 {
40 ReleaseCapture();//用来释放被当前线程中某个窗口捕获的光标 41 SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);//向Windows发送拖动窗体的消息 42 } 43 } 44 }

Frm_Main.designer.cs

View Code
1 namespace DragNoFrameForm  2 {
3 partial class Frm_Main 4 {
5 /// 6 /// 必需的设计器变量。 7 /// 8 private System.ComponentModel.IContainer components = null; 9 10 /// 11 /// 清理所有正在使用的资源。 12 /// 13 /// 如果应释放托管资源,为 true;否则为 false。 14 protected override void Dispose(bool disposing) 15 {
16 if (disposing && (components != null)) 17 {
18 components.Dispose(); 19 } 20 base.Dispose(disposing); 21 } 22 23 #region Windows 窗体设计器生成的代码 24 25 /// 26 /// 设计器支持所需的方法 - 不要 27 /// 使用代码编辑器修改此方法的内容。 28 /// 29 private void InitializeComponent() 30 {
31 this.components = new System.ComponentModel.Container(); 32 this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); 33 this.ExitContext = new System.Windows.Forms.ToolStripMenuItem(); 34 this.contextMenuStrip1.SuspendLayout(); 35 this.SuspendLayout(); 36 // 37 // contextMenuStrip1 38 // 39 this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
40 this.ExitContext}); 41 this.contextMenuStrip1.Name = "contextMenuStrip1"; 42 this.contextMenuStrip1.Size = new System.Drawing.Size(101, 26); 43 // 44 // ExitContext 45 // 46 this.ExitContext.Name = "ExitContext"; 47 this.ExitContext.Size = new System.Drawing.Size(100, 22); 48 this.ExitContext.Text = "退出"; 49 this.ExitContext.Click += new System.EventHandler(this.ExitContext_Click); 50 // 51 // Frm_Main 52 // 53 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 54 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 55 this.BackgroundImage = global::DragNoFrameForm.Properties.Resources._04; 56 this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; 57 this.ClientSize = new System.Drawing.Size(320, 228); 58 this.ContextMenuStrip = this.contextMenuStrip1; 59 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; 60 this.Name = "Frm_Main"; 61 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 62 this.Text = "拖动无边框窗体"; 63 this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Frm_Main_MouseDown); 64 this.contextMenuStrip1.ResumeLayout(false); 65 this.ResumeLayout(false); 66 67 } 68 69 #endregion 70 71 private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; 72 private System.Windows.Forms.ToolStripMenuItem ExitContext; 73 } 74 }

作者:
出处:
关于作者:专注于.Net、WCF和移动互联网开发。
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,如有问题,可以通过ynbt_wang@163.com联系我,非常感谢。 。

转载于:https://www.cnblogs.com/wifi/articles/2473274.html

你可能感兴趣的文章
如何在CentOS 7上修改主机名
查看>>
puppet自动化运维之tag标签puppet自动化运维之tag标签
查看>>
常见问题kernel调优
查看>>
通过vftps和虚拟帐号增强ftp的安全性
查看>>
20个最新的照片 PS 技巧,提升摄影水平
查看>>
通过SAN(Subject Alternative Name)实现证书的多域名安全访问
查看>>
RHEL6 搭建 keepalived + lvs/DR 集群
查看>>
easypanel 的 PHP5.4-7.0 插件
查看>>
System Center Operations Manager 2012 SP1 处理“未监控”对象
查看>>
JQuery链式操作学习对比
查看>>
VXLAN 概念(Part II)- 每天5分钟玩转 OpenStack(109)
查看>>
ASP.NET实际项目演练(1)
查看>>
Java虚拟机的简单介绍
查看>>
OC语法总结
查看>>
codeforces B. Pasha and String(贪心)
查看>>
关于Spring主题的使用心得
查看>>
Outlook小贴士之:撤回和替换邮件
查看>>
Windows Phone 实用开发技巧(30):Pivot切换时同时渐变背景图片
查看>>
利用pg_trgm的gist和gin索引加速字符匹配查询
查看>>
锐起无盘XP安装与配置图文(二)
查看>>