以前用到这样的功能都是通过vb.6.0升级得到,一直比较懒~今天没事,写了一下~还不算难~没有判断是否是右键单击~
先将 FormBorderStyle 设置为 FormBorderStyle.None,然后:

 Dim theScreen As Rectangle
    
Dim MousX As Short
    
Dim MousY As Short
    
Dim CurrX As Short
    
Dim CurrY As Short
    
Dim MoveScreen As Boolean
    
Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load
        theScreen 
= Screen.PrimaryScreen.Bounds()
        Me.Location 
= New Point((theScreen.Width - Me.Width) / 2, (theScreen.Height - Me.Height) / 2)     
    
End Sub


    
Private Sub Form1_MouseMove(ByVal sender As ObjectByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
        CurrX 
= Me.Left - MousX + e.X
        CurrY 
= Me.Top - MousY + e.Y
        
If MoveScreen = True Then
            Me.Location 
= New Point(CurrX, CurrY)
        
End If
    
End Sub


    
Private Sub Form1_MouseDown(ByVal sender As ObjectByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
        MousX 
= e.X
        MousY 
= e.Y
        MoveScreen 
= True
    
End Sub


    
Private Sub Form1_MouseUp(ByVal sender As ObjectByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
        MoveScreen 
= False
    
End Sub

posted on 2005-04-12 00:57  xyocj  阅读(434)  评论(0编辑  收藏  举报