Invoicing_Tube
{
    public partial class login : Form
    {
        
public login()
        {
            InitializeComponent();
        }
        
//定义一下坐标
        private Point mouseOffset;
        
//判断一下是否按下了左键默认的为False
        private bool isMouseDown = false;
        
private void login_MouseDown(object sender, MouseEventArgs e)
        {
            
try
            {
                
//X轴
                int xOffset;
                
//Y轴
                int yOffset;
                
//当按下左键时
                if (e.Button == MouseButtons.Left)
                {
                     
//X轴为当前的位置加上窗体的长度
                    xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
                    
//Y轴为当前的位置加上窗体的高度
                    yOffset = -e.Y - SystemInformation.CaptionHeight -
                        SystemInformation.FrameBorderSize.Height;
                    
//综合一下坐标
                    mouseOffset = new Point(xOffset, yOffset);
                    
//表示按下了左键
                    isMouseDown = true;
                }
            }
            
catch (Exception ee)
            {
                MessageBox.Show(ee.Message.ToString(), 
"提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        
private void login_MouseMove(object sender, MouseEventArgs e)
        {
            
try
            {
                
//如果按下了左键
                if (isMouseDown)
                {
                    
//前当的坐标==鼠标的位置
                    Point mousePos = Control.MousePosition;
                    mousePos.Offset(mouseOffset.X, mouseOffset.Y);
                    Location 
= mousePos;
                }
            }
            
catch (Exception ee)
            {
                MessageBox.Show(ee.Message.ToString(), 
"提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        
private void login_MouseUp(object sender, MouseEventArgs e)
        {
            
try
            {
                
if (e.Button == MouseButtons.Left)
                {
                    isMouseDown 
= false;
                }
            }
            
catch (Exception ee)
            {
                MessageBox.Show(ee.Message.ToString(), 
"提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
    }
}

下载全部代码:http://www.cckan.net/forum.php?mod=viewthread&tid=68

相关文章:

  • 2021-10-01
  • 2021-03-31
  • 2022-12-23
  • 2021-12-17
  • 2021-08-19
  • 2022-12-23
猜你喜欢
  • 2021-06-27
  • 2021-06-26
  • 2022-12-23
  • 2022-12-23
  • 2021-08-05
  • 2021-08-19
  • 2022-12-23
相关资源
相似解决方案