拖动无标题栏的窗体,需要处理的三个事件

ExpandedBlockStart.gif 代码
 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 
10  namespace  Invoicing_Tube
11  {
12       public   partial   class  login : Form
13      {
14           public  login()
15          {
16              InitializeComponent();
17          }
18           // 定义一下坐标
19           private  Point mouseOffset;
20           // 判断一下是否按下了左键默认的为False
21           private   bool  isMouseDown  =   false ;
22           private   void  login_MouseDown( object  sender, MouseEventArgs e)
23          {
24               try
25              {
26                   // X轴
27                   int  xOffset;
28                   // Y轴
29                   int  yOffset;
30                   // 当按下左键时
31                   if  (e.Button  ==  MouseButtons.Left)
32                  {
33                        // X轴为当前的位置加上窗体的长度
34                      xOffset  =   - e.X  -  SystemInformation.FrameBorderSize.Width;
35                       // Y轴为当前的位置加上窗体的高度
36                      yOffset  =   - e.Y  -  SystemInformation.CaptionHeight  -
37                          SystemInformation.FrameBorderSize.Height;
38                       // 综合一下坐标
39                      mouseOffset  =   new  Point(xOffset, yOffset);
40                       // 表示按下了左键
41                      isMouseDown  =   true ;
42                  }
43              }
44               catch  (Exception ee)
45              {
46                  MessageBox.Show(ee.Message.ToString(),  " 提示信息 " , MessageBoxButtons.OK, MessageBoxIcon.Warning);
47              }
48          }
49 
50           private   void  login_MouseMove( object  sender, MouseEventArgs e)
51          {
52               try
53              {
54                   // 如果按下了左键
55                   if  (isMouseDown)
56                  {
57                       // 前当的坐标==鼠标的位置
58                      Point mousePos  =  Control.MousePosition;
59                      mousePos.Offset(mouseOffset.X, mouseOffset.Y);
60                      Location  =  mousePos;
61                  }
62              }
63               catch  (Exception ee)
64              {
65                  MessageBox.Show(ee.Message.ToString(),  " 提示信息 " , MessageBoxButtons.OK, MessageBoxIcon.Warning);
66              }
67          }
68 
69           private   void  login_MouseUp( object  sender, MouseEventArgs e)
70          {
71               try
72              {
73                   if  (e.Button  ==  MouseButtons.Left)
74                  {
75                      isMouseDown  =   false ;
76                  }
77              }
78               catch  (Exception ee)
79              {
80                  MessageBox.Show(ee.Message.ToString(),  " 提示信息 " , MessageBoxButtons.OK, MessageBoxIcon.Warning);
81              }
82          }
83      }
84  }
85 
86 

 

文章转自: http://home.cnblogs.com/sufei/

转载于:https://www.cnblogs.com/angleSJW/archive/2010/08/23/1806315.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值