蓝派网(www.lan27.com)-精选网络资源,分享和交流! 文章首页站内搜索在线手册广告代码酷站欣赏万年历
您现在的位置: 蓝派网 >> 文章中心 >> 网络编程 >> .NET >> VB.NET >> 正文

如何拖动没有边框的窗体?

作者:孟宪会    文章来源:网络    更新时间:2007-6-4 23:55:44

这个功能在VB6中,需要借助于API函数才能实现。而在VB.NET中,凭自己的功能就能实现。首先设置窗体的FormBorderStyle属性为none以去掉窗体的边框,然后在窗体上添加一个按钮。窗体中的代码如下:

Public Class Form1  Inherits System.Windows.Forms.Form  Private mouse_offset As Point  Private Sub form1_MouseDown(ByVal sender As Object, _ ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown   mouse_offset = New Point(e.X, e.Y)  End Sub Private Sub form1_MouseMove(ByVal Sender As System.Object, _ ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove  '按住鼠标左右键均可拖动窗体  If e.Button = MouseButtons.Left Or e.Button = MouseButtons.Right Then   Dim mousePos As Point = Sender.findform().MousePosition   '获得鼠标偏移量   mousePos.Offset(-mouse_offset.X, -mouse_offset.Y)   '设置窗体随鼠标一起移动   Sender.findform().Location = mousePos  End If End Sub Private Sub BtnExit_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click  '关闭窗体  Me.Close() End Sub End Class

 
【相关文章:】
没有相关文章

发表评论】【打印此文】【关闭窗口】【点击数:
★好玩的休闲小游戏★