CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  基础类

按钮的拖动问题!急急!!!

楼主lxb529()2002-04-16 16:00:18 在 VB / 基础类 提问

我想实现当鼠标移动到按钮上时我移动鼠标向下的时候按钮的高度会随着鼠标的移动变高,同样对于向右移动的时候,按钮的宽度页会随着变宽,(前提是该按钮的  
  top,和left都不变变得只是宽度和高度)!!!!  
        望各位大侠赐教!!! 问题点数:80、回复次数:10Top

1 楼ayuu(ayuu)回复于 2002-04-16 16:09:16 得分 70

command_MouseDown(button   as   integer,shift   as   integer,x   as   single,y   as   single)  
  px=x  
  py=y  
  end   sub  
   
  command_MouseMove(button   as   integer,shift   as   integer,x   as   single,y   as   single)  
  command.height=command.height+x-px  
  command.width=command.width+y-py  
  command.left=inileft  
  command.top=initop  
  end   sub  
   
  其中,inileft,initop分别是按钮最初位置的left和top值,是不变的。Top

2 楼lxb529()回复于 2002-04-16 16:27:28 得分 0

试了,可是MouseDown发生在mousemove后,所以对于,px,py在mousedown中的  
  付值好像没用,Top

3 楼ayuu(ayuu)回复于 2002-04-16 16:29:22 得分 0

哎呀,px和py你要定义为全局变量的。  
  这样肯定可以的。我常用这个方法的。Top

4 楼ayuu(ayuu)回复于 2002-04-16 16:30:41 得分 0

哦,补充一下。  
  command_MouseMove(button   as   integer,shift   as   integer,x   as   single,y   as   single)  
  if   button=1   then  
  command.height=command.height+x-px  
  command.width=command.width+y-py  
  command.left=inileft  
  command.top=initop  
  endif  
  end   sub  
   
  这样就可以了。前面忘记写这句判断了。:)  
  Top

5 楼lxb529()回复于 2002-04-16 16:32:04 得分 0

按钮只要一拖动就变得很大,不是扩充到鼠标移动的位置!   ayuu(ayuu)大侠  
  请指教!谢谢!Top

6 楼ayuu(ayuu)回复于 2002-04-16 18:04:44 得分 0

Dim   px   As   Single,   py   As   Single,   iniheight   As   Single,   iniwidth   As   Single  
   
   
  Private   Sub   Command1_MouseDown(Button   As   Integer,   Shift   As   Integer,   X   As   Single,   Y   As   Single)  
  px   =   X  
  py   =   Y  
   
  End   Sub  
   
  Private   Sub   Command1_MouseMove(Button   As   Integer,   Shift   As   Integer,   X   As   Single,   Y   As   Single)  
  If   Button   =   1   Then  
  Command1.Height   =   iniheight   +   Y   -   py  
  Command1.Width   =   iniwidth   +   X   -   px  
  End   If  
   
   
  End   Sub  
   
   
  Private   Sub   Form_Load()  
  iniheight   =   Command1.Height  
  iniwidth   =   Command1.Width  
  End   Sub  
   
   
  我试过了,肯定没有问题啦。Top

7 楼ayuu(ayuu)回复于 2002-04-16 18:05:54 得分 0

当然,你应该还要注意反向的拖动时,控件的高度和宽度不能小于0。这个判断就自己加吧。Top

8 楼505(五五)回复于 2002-04-16 19:14:51 得分 0

 
   
  按钮只要一拖动就变得很大,不是扩充到鼠标移动的位置!    
   
  ==================================================  
   
  可能是你的   Form1.ScaleMode=3(pixel)的缘故Top

9 楼xxlroad(土八路)回复于 2002-04-16 19:27:01 得分 0

'同意:   ayuu(ayuu)    
  Dim   px   As   Single,   py   As   Single  
  Dim   iniheight   As   Single,   iniwidth   As   Single  
   
  Private   Sub   Command1_MouseDown(Button   As   Integer,   Shift   As   Integer,   X   As   Single,   Y   As   Single)  
          px   =   X  
          py   =   Y  
  End   Sub  
   
  Private   Sub   Command1_MouseMove(Button   As   Integer,   Shift   As   Integer,   X   As   Single,   Y   As   Single)  
          If   Button   =   1   And   (iniheight   +   Y   -   py)   >   0   And   (iniwidth   +   X   -   px)   >   0   Then  
                  Command1.Height   =   iniheight   +   Y   -   py  
                  Command1.Width   =   iniwidth   +   X   -   px  
          End   If  
  End   Sub  
   
  Private   Sub   Form_Load()  
          iniheight   =   Command1.Height  
          iniwidth   =   Command1.Width  
  End   SubTop

10 楼xxlroad(土八路)回复于 2002-04-16 19:37:00 得分 10

Option   Explicit  
   
  Private   Declare   Function   GetWindowLong   Lib   "user32"   Alias   "GetWindowLongA"   (ByVal   hwnd   As   Long,   ByVal   nIndex   As   Long)   As   Long  
  Private   Declare   Function   SetWindowLong   Lib   "user32"   Alias   "SetWindowLongA"   (ByVal   hwnd   As   Long,   ByVal   nIndex   As   Long,   ByVal   dwNewLong   As   Long)   As   Long  
  Private   Declare   Function   SetWindowPos   Lib   "user32"   (ByVal   hwnd   As   Long,   ByVal   hWndInsertAfter   As   Long,   ByVal   x   As   Long,   ByVal   y   As   Long,   ByVal   cx   As   Long,   ByVal   cy   As   Long,   ByVal   wFlags   As   Long)   As   Long  
  Const   SWP_NOSIZE   =   &H1  
  Const   SWP_NOZORDER   =   &H4  
  Const   SWP_NOMOVE   =   &H2  
  Const   SWP_DRAWFRAME   =   &H20  
  Const   GWL_STYLE   =   (-16)  
  Const   WS_THICKFRAME   =   &H40000  
   
  Private   Sub   Command1_Click()   '允许改变控件尺寸  
          ResizeControl   Text1,   Me  
  End   Sub  
   
  Sub   ResizeControl(ControlName   As   Control,   FormName   As   Form)  
  Dim   NewStyle   As   Long  
          NewStyle   =   GetWindowLong(ControlName.hwnd,   GWL_STYLE)  
          NewStyle   =   NewStyle   Or   WS_THICKFRAME  
          NewStyle   =   SetWindowLong(Text1.hwnd,   GWL_STYLE,   NewStyle)  
          SetWindowPos   ControlName.hwnd,   FormName.hwnd,   0,   0,   0,   0,   SWP_NOZORDER   Or   SWP_NOSIZE   Or   SWP_NOMOVE   Or   SWP_DRAWFRAME  
  End   SubTop

相关问题

  • 如何拖动按钮
  • 如何使用按钮拖动窗体?
  • 实现可拖动的按钮
  • 急急急!!!没有边框如何拖动窗体???
  • 急!急!急!急 如何写不规则的按钮?
  • 如何在对话框程序中实现按钮的拖动?
  • 请问如何使按钮可以自由拖动
  • 请问怎样实现可以拖动的按钮
  • 急急急!!!高手帮忙----怎样使TreeView,ListView控件的大小能拖动
  • 急!急!怎样使MessagBox不能被拖动?

关键词

  • 鼠标
  • 移动
  • top
  • iniheight
  • iniwidth
  • 按钮
  • single
  • 拖动
  • ayuu
  • pycommand

得分解答快速导航

  • 帖主:lxb529
  • ayuu
  • xxlroad

相关链接

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

广告也精彩

反馈

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