新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > 开发语言 > VB教程 > 正文:VB.NET 拖动无边框窗体编程实例

VB.NET 拖动无边框窗体编程实例

新客网 XKER.COM 2007-06-18 来源: 收藏本文
Imports System.Drawing
Imports System.Windows.Forms
'******************************************
  Private oOriginalRegion As Region = Nothing
  ' 用于窗体移动
  Private bFormDragging As Boolean = False
  Private oPointClicked As Point

  '******************************************

  Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown

  Me.bFormDragging = True
  Me.oPointClicked = New Point(e.X, e.Y)

  End Sub
  '******************************************

  Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
  Me.bFormDragging = False

  End Sub
  '******************************************

  Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
  If Me.bFormDragging Then
  Dim oMoveToPoint As Point
  ' 以当前鼠标位置为基础,找出目标位置
  oMoveToPoint = Me.PointToScreen(New Point(e.X, e.Y))
  ' 根据开始位置作出调整
  oMoveToPoint.Offset(Me.oPointClicked.X * -1, _
  (Me.oPointClicked.Y + _
  SystemInformation.CaptionHeight + _
  SystemInformation.BorderSize.Height) * -1)
  ' 移动窗体
  Me.Location = oMoveToPoint
  End If

  End Sub

收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
阅读排行
随机推荐
实用信息推荐