command控件组移动的问题

zoomwe 2008-03-18 09:33:43
我让command1移动是下面的代码:
Dim Xx, Yy
Private Sub command1_MouseDown(Button As Integer, Shift As Integer, X As Single, y As Single)
If Button = 1 Then
Xx = X
Yy = y
End If
End Sub

Private Sub command1_MouseMove(Button As Integer, Shift As Integer, X As Single, y As Single)
If Button = 1 Then
Command1.Left = X - Xx + Command1.Left
Command1.Top = y - Yy + Command1.Top
End If
End Sub

但是我用command1建了一个数组,有三十个
请问我怎么样让command1(0),command1(1),command1(2),.....分别用鼠标来移动啊.


另外顺便问个小问题:command控件可以变成圆的吗?我想用它来做指示灯(红绿灯).
...全文
77 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
嗷嗷叫的老马 2008-03-18
  • 打赏
  • 举报
回复
请问我怎么样让command1(0),command1(1),command1(2),.....分别用鼠标来移动啊.

//

个人建议:

如果你是想用这些按钮作为显示用而不是要使用它的单击功能,那就使用对象思想,设计每个"图形"为一个对象.

这样就方便使用与管理.
cbm6666 2008-03-18
  • 打赏
  • 举报
回复
做指示灯(红绿灯)用Shape控件不是更好做吗?

'窗体上加一个 Command1(0)

Option Explicit
'*****************************************移动窗体的API
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 Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2
Dim i%

Private Sub Form_Load()
For i = 1 To 29
Load Command1(i)
Command1(i).Visible = True
Next i
End Sub

Private Sub Command1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Call ReleaseCapture
Call SendMessage(Command1(Index).hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End If
End Sub



forbearORfolie 2008-03-18
  • 打赏
  • 举报
回复
如果是控件数组,可以通过index访问
做红绿灯可以用image载入图片,vb自带的资源里有。也可以用shape控件

1,453

社区成员

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

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