정상적으로 작동하는 것처럼 보이지만 마우스 클릭 만 감지하면 많은 코드처럼 보입니다. 예를 들어, 모든 폼 컨트롤을 포함하는 클래스를 만들 수 있어야한다고 생각하여 각 컨트롤을 개별적으로 확인하지 않고 한 번에 클릭을 감지 할 수있었습니다. 나는 그 일을 할 수 없었고 나는 누군가가 이것을 개선 할 수 있기를 바라고 있습니다.
사용자 삽입 이미지 사용자 폼에서 mapFrame이라는 이름의 큰 프레임에는 다른 프레임과 레이블이 여러 개 포함되어 있으며 포함 된 모든 프레임에는 다른 프레임과 레이블이 여러 개있을 수 있습니다. 중첩됩니다. 루프를 시작하고 싶습니다 (이 경우 루프는 컨트롤을 껐다가 켭니다.하지만 다른 루프가 될 수 있음). 사용자가 포함 된 프레임이나 레이블 중 하나를 클릭하여 루프에서 이탈 신호를 기다립니다. . 나는 또한 클릭 한 컨트롤의 이름을 얻고 싶다.
나는 therealmarv의 제안을 받아 루프 내에서 테스트되는 공개 부울을 설정하기 위해 클릭을 사용했습니다. 또 다른 새로운 클래스 모듈에서
Option Explicit
Public WithEvents classLabels As msForms.Label
Private Sub classLabels_Click()
clickedControlName = "" '<== Public String
With classLabels
If .Parent.Name = "mapFrame" Or _
.Parent.Parent.Name = "mapFrame" Then
isClickDetected = True '<== Public Boolean
clickedControlName = .Name
End If
End With
End Sub
:
Option Explicit
Public WithEvents classFrames As msForms.Frame
Private Sub classFrames_Click()
clickedControlName = "" '<== Public String
With classFrames
If .Name = "mapFrame" Or _
.Parent.Name = "mapFrame" Or _
.Parent.Parent.Name = "mapFrame" Then
isClickDetected = True '<== Public Boolean
clickedControlName = .Name
End If
End With
End Sub
양식 모듈 :
Option Explicit
Dim frames() As New clsFrames
Dim labels() As New clsLabels
Private Sub createFrameListeners()
Dim ctl As msForms.Control
Dim frameCount as Long
For Each ctl In Me.Controls
' Debug.Print TypeName(ctl): Stop
If TypeName(ctl) = "Frame" Then
frameCount = frameCount + 1
ReDim Preserve frames(1 To frameCount)
'Create the Frame Listener objects
Set frames(frameCount).classFrames = ctl
End If
Next ctl
End Sub
Private Sub createLabelListeners()
Dim ctl As msForms.Control
Dim LabelCount as Long
For Each ctl In Me.Controls
' Debug.Print TypeName(ctl): Stop
If TypeName(ctl) = "Label" Then
LabelCount = LabelCount + 1
ReDim Preserve labels(1 To LabelCount)
'Create the Label Listener objects
Set labels(LabelCount).classLabels = ctl
End If
Next ctl
End Sub
Function blinkThisControl(ctrl As Control, ByVal blinkCount As Long)
isClickDetected = False
Dim i As Integer
For i = 1 To blinkCount
' <blink ctrl twice>
DoEvents
If isClickDetected Then Exit Function
'name of clicked control will be in clickedControlName
Next i
End Function
Private Sub userform_initialize()
Call createFrameListeners
Call createLabelListeners
' do other stuff
End Sub
출처
2011-08-15 06:55:47
Roy
이 그 비전 검사 곳 중 하나 같은 소리 새로운 클래스 모듈에서
특정 번호가 나타나면 마우스를 클릭하라고합니다. p – aevanko좋은 질문입니다. 어쩌면 트리거 또는 뭔가를 설정하는 API 함수. 사실, 좋은 대답을 기대합니다. BTW, 첫 번째 답변에 대한 귀하의 의견도 문제를 해결할 수 있다고 생각합니다. – Oneide