惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

月光博客
月光博客
MyScale Blog
MyScale Blog
博客园 - Franky
The Cloudflare Blog
IT之家
IT之家
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
WordPress大学
WordPress大学
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
The Blog of Author Tim Ferriss
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
Google DeepMind News
Google DeepMind News
P
Proofpoint News Feed
Martin Fowler
Martin Fowler
aimingoo的专栏
aimingoo的专栏
J
Java Code Geeks
腾讯CDC
雷峰网
雷峰网
Microsoft Azure Blog
Microsoft Azure Blog
G
Google Developers Blog
博客园 - 【当耐特】
美团技术团队
云风的 BLOG
云风的 BLOG

博客园 - Dawnxu

修改的Flash + ASP.NET 拍照程序 AjaxPro在Windows 2000 server下不能正常使用的解决方案 MSN 8.0 邀请函! RAR 命令 新版XNet.SqlHelper 很不错的Windows 控件 Developer Express Inc.NET 61条面向对象设计的经验原则 两个WEB程序之间的通信 本人还有50份GMail邀请函,要的请留言! 关于俱乐部活动的个人想法! 操作MS SQL Server 存储过程的类(外加ASP.NET MessageBox类) 修改的一个Title提示 大学毕业了再看你会后悔一辈子的 妙用Asp.Net中的HttpHandler [转载]ASP.NET分页的处理方式 [转载]ASP.NET开发经验积累 WINDOWS2000开机硬盘自动共享 [转载]无组件上传程序ASP.NET版 C#实现的根据年月日计算星期几的函数
鼠标按住任意控件拖动窗口
Dawnxu · 2005-12-21 · via 博客园 - Dawnxu

Imports System.Drawing.Point

Public Class Move
    
Private WithEvents control As System.Windows.Forms.Control
    
Private mouse_offset As Point
    
Private frm As Form

    
Public Sub New(ByVal theControl As System.Windows.Forms.Control, ByVal theForm As Form)
        
Me.control = theControl '鼠标拖动的控件
        Me.frm = theForm '要移动的窗口
    End Sub

    
Private Sub GroupControl1_MouseDown(ByVal sender As ObjectByVal e As System.Windows.Forms.MouseEventArgs) Handles control.MouseDown
        mouse_offset 
= New Point(e.X, e.Y)
    
End Sub


    
Private Sub GroupControl1_MouseMove(ByVal sender As ObjectByVal e As System.Windows.Forms.MouseEventArgs) Handles control.MouseMove

        
If (e.Button = MouseButtons.Left Or e.Button = MouseButtons.Right) Then
            
Dim mousePos As Point = frm.MousePosition
            
'获得鼠标偏移量
            mousePos.Offset(-mouse_offset.X, -mouse_offset.Y)
            
'设置窗体随鼠标一起移动
            frm.Location = mousePos
        
End If

    
End Sub

End Class

使用:

在窗口加载时:

Move move = new Move(this.label1,this)
这样鼠标按住 label1 拖动时,窗口就会移动。