熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

如何拖動沒有邊框的窗體?

2013-11-13 10:13:01  來源: .NET編程 

  這個功能在VB需要借助於API函數才能實現而在中憑自己的功能就能實現首先設置窗體的FormBorderStyle屬性為none以去掉窗體的邊框然後在窗體上添加一個按鈕窗體中的代碼如下

  Public Class Form
  Inherits System<a _blank>Windows</a>FormsForm

  Private mouse_offset As Point
  Private Sub form_MouseDown(ByVal sender As Object _
   ByVal e As SystemWindowsFormsMouseEventArgs) Handles MyBaseMouseDown
   mouse_offset = New Point(eX eY)
  End Sub

  Private Sub form_MouseMove(ByVal Sender As SystemObject _
  ByVal e As SystemWindowsFormsMouseEventArgs) Handles MyBaseMouseMove
  按住鼠標左右鍵均可拖動窗體
  If eButton = MouseButtonsLeft Or eButton = MouseButtonsRight Then
   Dim mousePos As Point = Senderfindform()MousePosition
   獲得鼠標偏移量
   mousePosOffset(mouse_offsetX mouse_offsetY)
   設置窗體隨鼠標一起移動
   Senderfindform()Location = mousePos
  End If
 End Sub

  Private Sub BtnExit_Click(ByVal sender As SystemObject _
  ByVal e As SystemEventArgs) Handles ButtonClick
  關閉窗體
  MeClose()
 End Sub
 End Class


From:http://tw.wingwit.com/Article/program/net/201311/12947.html
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.