Klassenmodule ?
04.11.2008 18:17:00
ransi
HAllo Stephan
Ich wage mich mal in die Welt der Klassen Programmierung.
Jede Menge OptionButtons und TextBoxen in vielen Frames auf deiner Userform:
Versuch mal dies:
' **********************************************************************
' Modul: clsControls Typ: Klassenmodul
' **********************************************************************
Option Explicit
Public WithEvents DieTBs As MSForms.TextBox
Public WithEvents DieOBs As MSForms.OptionButton
Private Sub DieOBs_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Select Case Button
Case 1: MsgBox "Linke Maus auf " & DieOBs.Name & vbCrLf & DieOBs.Parent.Name
Case 2: MsgBox "Rechte Maus auf " & DieOBs.Name & vbCrLf & DieOBs.Parent.Name
Case 4: MsgBox "Mittlere Maus auf " & DieOBs.Name & vbCrLf & DieOBs.Parent.Name
End Select
End Sub
Private Sub DieTBs_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Select Case Button
Case 1: MsgBox "Linke Maus auf " & DieTBs.Name & vbCrLf & DieTBs.Parent.Name
Case 2: MsgBox "Rechte Maus auf " & DieTBs.Name & vbCrLf & DieTBs.Parent.Name
Case 4: MsgBox "Mittlere Maus auf " & DieTBs.Name & vbCrLf & DieTBs.Parent.Name
End Select
End Sub
' **********************************************************************
' Modul: UserForm1 Typ: Userform
' **********************************************************************
Option Explicit
Dim varTB() As New clsControls
Dim varOB() As New clsControls
Private Sub UserForm_Initialize()
Dim i As Integer
Dim L As Integer
Dim ctrl As MSForms.Control
Dim objTB As MSForms.TextBox
Dim objOB As MSForms.OptionButton
For Each ctrl In Me.Controls
Select Case TypeName(ctrl)
Case "TextBox"
Redim Preserve varTB(i)
Set varTB(i).DieTBs = ctrl
i = i + 1
Case "OptionButton"
Redim Preserve varOB(L)
Set varOB(L).DieOBs = ctrl
L = L + 1
End Select
Next
End Sub
ransi