c#无边框窗口的入门级拖动实现
来源:互联网 发布:身份证被盗用网络贷款 编辑:程序博客网 时间:2024/05/22 00:36
实现了窗口的移动,下一步研究通过菜单拖动窗口
//窗口无任何控件
以下为form1.cs中的全部代码 多出的部分为添加部分(自行寻找)
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Runtime.InteropServices;namespace WindowsFormsApplication9{ public partial class Form1 : Form { #region 本程序中用到的API函数 [DllImport("user32.dll")] public static extern bool ReleaseCapture(); [DllImport("user32.dll")] public static extern bool SendMessage(IntPtr hwdn, int wMsg, int mParam, int lParam); #endregion #region 本程序中需要声明的变量 public const int WM_SYSCOMMAND = 0x0112;//该变量表示将向Windows发送的消息类型 public const int SC_MOVE = 0xF010;//该变量表示发送消息的附加消息 public const int HTCAPTION = 0x0002;//该变量表示发送消息的附加消息 #endregion private void ExitContext_Click(object sender, EventArgs e) { Application.Exit();//退出本程序 } private void Form1_MouseDown(object sender, MouseEventArgs e) { ReleaseCapture(); SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); } public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } }}
以下代码为form1.designer.cs中的代码,改动代码已标记
namespace WindowsFormsApplication9{ partial class Form1 { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </summary> private void InitializeComponent() { //此处为添加代码********* this.components = new System.ComponentModel.Container(); this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); this.ExitContext = new System.Windows.Forms.ToolStripMenuItem(); this.contextMenuStrip1.SuspendLayout(); //至此********** this.SuspendLayout(); // // Form1 // //此处为添加代码************* this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ExitContext}); this.contextMenuStrip1.Name = "contextMenuStrip1"; this.contextMenuStrip1.Size = new System.Drawing.Size(101, 26); // // ExitContext // this.ExitContext.Name = "ExitContext"; this.ExitContext.Size = new System.Drawing.Size(100, 22); this.ExitContext.Text = "退出"; this.ExitContext.Click += new System.EventHandler(this.ExitContext_Click); // // Frm_Main // //至此**************** this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; //此处为添加代码********** this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; //至此****************** this.ClientSize = new System.Drawing.Size(284, 262); //此处为添加代码*********** this.ContextMenuStrip = this.contextMenuStrip1; //至此******************* this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Name = "Form1"; //此处为添加代码 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; //至此************* this.Text = "Form1"; //此处为添加代码 this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown); this.contextMenuStrip1.ResumeLayout(false); //至此************ this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); } #endregion private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; private System.Windows.Forms.ToolStripMenuItem ExitContext; }}
望互相交流。
0 0
- c#无边框窗口的入门级拖动实现
- C# 无边框窗口实现拖动
- C# 实现无边框窗口拖动
- C# API拖动无边框窗口
- C# 鼠标拖动WinForm无边框窗口
- 实现无边框可拖动调整大小的阴影窗口
- 实现无边框时拖动窗口
- WinForm 无边框窗口 拖动实现
- 无边框窗口拖动
- C#实现无边框窗体拖动的两个方案
- c#.net无边框窗口的拖动!
- MFC中无边框窗口的拖动
- 无边框窗口的缩放与拖动
- MFC中无边框窗口的拖动
- C# 实现拖动无边框窗体
- C#实现无边框窗体拖动
- C#实现无边框窗体拖动
- C#中实现无边框窗体拖动
- Android之输入用户名和密码验证
- 学了好多东西,怕忘记就写一下吧
- sqlite之增删改查--简单的实现iOS收藏夹功能
- git远程回滚
- C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\rcdll.dll;E:\Program Files\VC\bin\rcdll.dll 无法找到资源
- c#无边框窗口的入门级拖动实现
- 下载网易公开课 视频 代码
- c#微信群发消息
- OD+IDA6.1破解HideWizard v9.29(无忧隐藏)【附下载】
- Lua-编译-运行-调试
- 一个字段同时满足多个条件的查询
- LeetCode Two Sum
- 线程安全的CGContext绘图
- 分享一下我的懒惰解决了一个棘手问题