Vb高手帮帮忙吧~~万分感激!!!!

catherine_spmc 2010-01-19 01:15:53
我现在初学,自己想做一些小程序,现在出现两个问题:
1:如何用鼠标左键按下来移动窗口,松开手,停止移动。
2:如何把几按钮控件嵌到一个大的按钮上,点击大按钮的任意一处,可以同时移动~
小女子在这感激不尽:)
...全文
161 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
cbm6666 2010-01-20
  • 打赏
  • 举报
回复
1. 添加 Text1 Picture1 试着拖动它们

Option Explicit
'*****************************************移动窗体
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Call DragKj(Me.hwnd)
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Call DragKj(Picture1.hwnd)
End Sub

Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Call DragKj(Text1.hwnd)
End Sub

Public Sub DragKj(HwndKj As Long)
On Error Resume Next
Call ReleaseCapture
Call SendMessage(HwndKj, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End Sub


'***************************************************
2 如何把几按钮控件嵌到一个大的按钮上 呵呵...思路有点怪

按钮不是容器 它无法装载其它控件, 也许你该换个思路 几个按钮控件嵌到一个PictureBox里面

'添加 Command1 Command2 Command3 Command4

hafizding 2010-01-20
  • 打赏
  • 举报
回复
给我分吧,呵呵!
chinaboyzyq 2010-01-19
  • 打赏
  • 举报
回复
1、
Dim t, tx, ty
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
t = True
tx = X
ty = Y
End If

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If t = True Then
Form1.Top = Y + Form1.Top - ty
Form1.Left = X + Form1.Left - tx
End If
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
t = False
End Sub

2、用picturebox做容器其它按钮的容器,并且它做大按钮。
catherine_spmc 2010-01-19
  • 打赏
  • 举报
回复
能不能说明白点呢?我初学,对库里的函数都不怎么熟悉
gz284596265 2010-01-19
  • 打赏
  • 举报
回复
第一个问题可以相应鼠标的move事件 定义一个参数与鼠标左键按下关联
如果鼠标按下 再执行移动操作 通过关联窗体的位置和鼠标指针的位置来实现窗体位置的移动
  • 打赏
  • 举报
回复
Cathy, 详细点。

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧