CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  基础类

如何拖动一个没有标题栏的窗体?

楼主starsoulxp(星魂)2003-06-03 12:48:36 在 VB / 基础类 提问

如何拖动一个没有标题栏的窗体? 问题点数:20、回复次数:5Top

1 楼ch21st(www.blanksoft.com)回复于 2003-06-03 13:10:45 得分 6

Public   Declare   Function   ReleaseCapture   Lib   "user32"   ()   As   Long  
   
  Public   Declare   Function   SendMessage   Lib   "user32"   Alias   "SendMessageA"   (ByVal   hwnd   As   Long,   ByVal   wMsg   As   Long,   ByVal   wParam   As   Long,   lParam   As   Any)   As   Long  
   
  'Public   Const   WM_SYSCOMMAND   =   &H112  
  'Public   Const   SC_MOVE   =   &HF012  
  Public   Const   HTCAPTION   =   2  
  Public   Const   WM_NCLBUTTONDOWN   =   &HA1  
   
  If   Button   =   vbLeftButton   Then  
  ReleaseCapture  
  SendMessage   Me.hwnd,   WM_NCLBUTTONDOWN,   HTCAPTION,   0&  
   
  End   IfTop

2 楼hengxin54(火星)回复于 2003-06-03 13:18:13 得分 5

Private   Declare   Function   SendMessage   Lib   "user32"   Alias   "SendMessageA"   (ByVal   hwnd   As   Long,   ByVal   wMsg   As   Long,   ByVal   wParam   As   Long,   lParam   As   Any)   As   Long  
  Private   Declare   Function   ReleaseCapture   Lib   "user32"   ()   As   Long  
   
   
  Private   Sub   Form_MouseDown(Button   As   Integer,   Shift   As   Integer,   X   As   Single,   Y   As   Single)  
          ReleaseCapture  
          SendMessage   Me.hwnd,   &HA1,   HTCAPTION,   0  
  End   SubTop

3 楼Fearfulness(谁都知道我最拽)回复于 2003-06-03 13:21:47 得分 2

在窗体的MouseMove事件里面加一些代码,可以实现.  
  x1,y1,为单击坐标form1.left=x-x1+form1.left       .top=y-y1+.top  
  要是用api可以看楼上的.Top

4 楼bydisplay(时光)回复于 2003-06-03 13:24:18 得分 4

Option   Explicit  
  'Variables  
  'Switch   to   turn   drah   on   and   off.  
  Dim   MoveScreen   As   Boolean  
  'Vars   to   get   the   mouse   position   on   the   form.  
  '       you   are   draging.  
  Dim   MousX   As   Integer  
  Dim   MousY   As   Integer  
  'Vars   for   moving   the   form.  
  Dim   CurrX   As   Integer  
  Dim   CurrY   As   Integer  
   
  Private   Sub   Form_MouseDown(Button   As   Integer,   Shift   As   Integer,   X   As   Single,   Y   As   Single)  
          MoveScreen   =   True   '   make   form   movable   while   the   mouse   is   down.  
          'Get   the   initial   coordinates   of   the   mouse   on   the   form.  
          MousX   =   X  
          MousY   =   Y  
  End   Sub  
   
  Private   Sub   Form_MouseMove(Button   As   Integer,   Shift   As   Integer,   X   As   Single,   Y   As   Single)  
                 
          'If   the   mouse   is   down   on   the   form   then.  
          If   MoveScreen   Then  
                  'Calculate   the   new   x,y   position   for   the   form.  
                  '       NB.   This   is   dependant   on   the   X   and   Y   vars   on   the   Form_MouseMove,  
                  '       you   can   use   objects   MouseMove   function.   i.e.   a   Label   or   Textbox.  
                  CurrX   =   Form1.Left   -   MousX   +   X  
                  CurrY   =   Form1.Top   -   MousY   +   Y  
                  'Move   the   form   to   the   new   X,Y.  
                  Form1.Move   CurrX,   CurrY           '   move   form.  
          End   If  
           
          'Display   the   new   X,Y   position   of   the   form.  
       
  End   Sub  
   
  Private   Sub   Form_MouseUp(Button   As   Integer,   Shift   As   Integer,   X   As   Single,   Y   As   Single)  
          MoveScreen   =   False         '   stop   the   form   from   moving.  
  End   Sub  
  Top

5 楼btone(子陵)回复于 2003-06-03 13:25:18 得分 3

Private   Sub   Form1_MouseDown(Button   As   Integer,   Shift   As   Integer,   X   As   Single,   Y   As   Single)  
          mouseIsDown   =   True  
          cx   =   X  
          cy   =   Y  
  End   Sub  
   
  Private   Sub   Form1_MouseMove(Button   As   Integer,   Shift   As   Integer,   X   As   Single,   Y   As   Single)  
          If   mouseIsDown   Then  
                '移动窗体  
                Move   Left   +   (X   -   cx),   Top   +   (Y   -   cy)  
          End   If  
  End   Sub  
   
  Private   Sub   Form1_MouseUp(Button   As   Integer,   Shift   As   Integer,   X   As   Single,   Y   As   Single)  
          mouseIsDown   =   False  
  End   SubTop

相关问题

  • 如何拖动没有标题栏的窗体??
  • 非标题栏窗体拖动问题
  • 如何用拖动的方法改变没有标题栏窗体的大小呢?
  • 一个无标题栏的窗体的拖动问题?
  • 求救::无标题栏的窗体拖动
  • 在没有标题栏的窗体中,怎样移动窗体?
  • ?如何判断当前是否在拖动窗体的标题栏??
  • 拖动无标题栏窗体时的出现问题?在线等待
  • 求能在Win98下用鼠标拖动没标题栏窗体的程序。
  • 鼠标按住标题栏拖动窗体时产生什么消息?

关键词

  • 窗体
  • htcaption
  • releasecapture
  • byval
  • sendmessage
  • hwnd
  • long
  • lib
  • user32
  • wm

得分解答快速导航

  • 帖主:starsoulxp
  • ch21st
  • hengxin54
  • Fearfulness
  • bydisplay
  • btone

相关链接

  • Visual Basic类图书
  • Visual Basic类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo