如何画一个方框并取得方框内所有的控件?

fishmans 2002-11-04 07:59:15
就像浏览器中拖动选取多个文件夹一样的效果!
...全文
55 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
fishmans 2002-11-12
  • 打赏
  • 举报
回复
为什么不能给分啊??
fishmans 2002-11-12
  • 打赏
  • 举报
回复
谢谢,这个问题我已经解决了~~~
junwhj 2002-11-10
  • 打赏
  • 举报
回复
Option Explicit

Private Declare Function DrawFocusRect Lib "user32" (ByVal hdc As Long, lpRect As RECT) As Long

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Type POINTAPI
X As Long
Y As Long
End Type

Private pt As POINTAPI
Private rc As RECT
Private blnMouseDown As Boolean

Private Sub Form_Load()
Me.ScaleMode = 3
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
pt.X = X
pt.Y = Y
blnMouseDown = True
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If blnMouseDown Then
DrawFocusRect Me.hdc, rc
rc.Left = IIf(pt.X < X, pt.X, X)
rc.Top = IIf(pt.Y < Y, pt.Y, Y)
rc.Right = IIf(pt.X > X, pt.X, X)
rc.Bottom = IIf(pt.Y > Y, pt.Y, Y)
DrawFocusRect Me.hdc, rc
Me.Refresh
End If
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim ctrl As Control

On Error Resume Next '有些控件不支持Left,Top属性(如Line)

For Each ctrl In Me.Controls
If ctrl.Left + ctrl.Width < rc.Left Or _
ctrl.Left > rc.Right Or _
ctrl.Top + ctrl.Height < rc.Top Or _
ctrl.Top > rc.Bottom Then
Else
Debug.Print ctrl.Name
End If
Next

blnMouseDown = False
End Sub

junwhj 2002-11-10
  • 打赏
  • 举报
回复
Option Explicit

Private Declare Function DrawFocusRect Lib "user32" (ByVal hdc As Long, lpRect As RECT) As Long

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Type POINTAPI
X As Long
Y As Long
End Type

Private pt As POINTAPI
Private rc As RECT
Private blnMouseDown As Boolean

Private Sub Form_Load()
Me.ScaleMode = 3
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
pt.X = X
pt.Y = Y
blnMouseDown = True
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If blnMouseDown Then
DrawFocusRect Me.hdc, rc
rc.Left = IIf(pt.X < X, pt.X, X)
rc.Top = IIf(pt.Y < Y, pt.Y, Y)
rc.Right = IIf(pt.X > X, pt.X, X)
rc.Bottom = IIf(pt.Y > Y, pt.Y, Y)
DrawFocusRect Me.hdc, rc
Me.Refresh
End If
End Sub

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

fishmans 2002-11-10
  • 打赏
  • 举报
回复
难道要遍历所有的在这个范围的控件??会不会太慢了点?还有就是我问的重点是如何实现画框的效果!!!
maxiuhui 2002-11-04
  • 打赏
  • 举报
回复
判断方框四角和控件坐标

1,486

社区成员

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

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