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 /// <summary>
6 /// 必需的设计器变量。
7 /// </summary>
8 private System.ComponentModel.IContainer components = null;
9
10 /// <summary>
11 /// 清理所有正在使用的资源。
12 /// </summary>
13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
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 /// <summary>
26 /// 设计器支持所需的方法 - 不要
27 /// 使用代码编辑器修改此方法的内容。
28 /// </summary>
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 }





作者:墨明棋妙
出处:http://www.cnblogs.com/ynbt/
关于作者:专注于.Net、WCF和移动互联网开发。
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,如有问题,可以通过ynbt_wang@163.com联系我,非常感谢。 。
 posted on 2012-04-27 11:56  纳米程序员  阅读(200)  评论(0编辑  收藏  举报