096457 ランダム
 ホーム | 日記 | プロフィール 【フォローする】 【ログイン】

続・頑張れ!ひろたん!

続・頑張れ!ひろたん!

イベント共有クラス

' ------------------------------------------
' クラスモジュール ( ExCtrls.cls )
' ------------------------------------------
Option Explicit

Public WithEvents ClsTextBox As TextBox
Public WithEvents ClsComboBox As ComboBox


Private Sub ClsComboBox_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        KeyAscii = 0
        SendKeys "{TAB}", True
    End If
End Sub

Private Sub ClsTextBox_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        KeyAscii = 0
        SendKeys "{TAB}", True
    End If
End Sub

Private Sub ClsTextBox_GotFocus()
    ClsTextBox.SelStart = 0
    ClsTextBox.SelLength = Len(ClsTextBox.Text)
End Sub


' --------------------------------------------
' フォームモジュール
' --------------------------------------------
Option Explicit

'モジュール変数
Private mExCtrls() As New ExCtrls

'フォームロード時
Private Sub Form_Load()
    
    ' 変数定義
    Dim objCtrl As Control
    Dim lngCnt As Long
    
    ' 初期化
    lngCnt = 0
    
    For Each objCtrl In Me.Controls
        ' テキストボックスをクラスに登録
        If TypeOf objCtrl Is TextBox Then
            ReDim Preserve mExCtrls(lngCnt)
            Set mExCtrls(lngCnt).ClsTextBox = objCtrl
            lngCnt = lngCnt + 1
        ' コンボボックスをクラスに登録
        ElseIf TypeOf objCtrl Is ComboBox Then
            ReDim Preserve mExCtrls(lngCnt)
            Set mExCtrls(lngCnt).ClsComboBox = objCtrl
            lngCnt = lngCnt + 1
        End If
    Next
End Sub



© Rakuten Group, Inc.