|
-
Mar 10th, 2005, 03:01 PM
#1
Thread Starter
Hyperactive Member
-
Mar 10th, 2005, 03:56 PM
#2
-
Mar 12th, 2005, 01:18 AM
#3
Re: Capture events from runtime controls
If your adding them at runtime you need to declare a WithEvents for it in
the general declarations section.
If your loading an array of controls based off of an initial one added in design
time then you would use that objects event and check the index of the
control that is received in the procedures Index parameter.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 12th, 2005, 04:38 AM
#4
Thread Starter
Hyperactive Member
Re: Capture events from runtime controls
Here is an example on how i create the runtime controls in a form! (command buttons)
VB Code:
Public Enum XControls
X_Command_Button = 0
X_Label = 1
X_TextBox = 2
X_Image = 3
X_ComboBox = 4
X_OptionButton = 5
X_CheckBox = 6
End Enum
Public Enum X_FontCharacteristics
xTrue = True
xFalse = False
End Enum
Public Enum X_FontSizes
Size_9 = 9
Size_10 = 10
Size_11 = 11
Size_12 = 12
Size_13 = 13
Size_14 = 14
Size_15 = 15
Size_16 = 16
Size_17 = 17
Size_18 = 18
Size_19 = 19
Size_20 = 20
Size_21 = 21
Size_22 = 22
Size_23 = 23
Size_24 = 24
Size_25 = 25
Size_26 = 26
Size_27 = 27
Size_28 = 28
Size_29 = 29
Size_30 = 30
End Enum
Public Enum X_Colors
Light_Red = &H8080FF
Red = &HFF&
Dark_Red = &HC0&
Blue = &HFF0000
Light_Green = &H80FF80
Green = &HFF00&
Dark_Green = &H8000&
Light_Blue = &HFFFF00
Dark_Blue = &HC00000
Orange = &H80FF&
Light_Orange = &H80C0FF
Dark_Orange = &H40C0&
Yellow = &HFFFF&
Black = &H0&
White = &HFFFFFF
Light_Grey = &HE0E0E0
Grey = &HC0C0C0
Dark_Grey = &H808080
Blue_Black = &H800000
Grey_Black = &H404040
Pink = &HFF80FF
Light_Pink = &HFFC0FF
Dark_Pink = &HFF00FF
End Enum
Private WithEvents CMD As CommandButton
Public Sub CreateControl(ControlType As XControls, Caption_Text As String, Height As Integer, Width As Integer, Top As Integer, Left As Integer, Optional Action As String, Optional Backcolor As X_Colors, Optional Forecolor As X_Colors, Optional FontName As String, Optional FontSize As X_FontSizes, Optional FontBold As X_FontCharacteristics, Optional FontItalic As X_FontCharacteristics, Optional FontStrikeThrough As X_FontCharacteristics)
Static countCMD As Integer
Select Case ControlType
'Check if it is Command Button
Case Is = 0
Set CMD = Me.Controls.Add("VB.CommandButton", "CMD" & countCMD + 1, Me)
'Change the value of the static variable for creating more controls
countCMD = countCMD + 1
With CMD
.Visible = True
'Check if there is fontname entered
If FontName <> "" Then
.Font = FontName
End If
'Check if there is fontsize entered
If FontSize <> 0 Then
.FontSize = FontSize
End If
'Check if there is fontbold entered
If FontBold <> 0 Then
.FontBold = FontBold
End If
'Check if there is fontitalic entered
If FontItalic <> 0 Then
.FontItalic = FontItalic
End If
'Check if there is fontStriked entered
If FontStrikeThrough <> 0 Then
.FontStrikethru = FontStrikeThrough
End If
.Width = Width
.Height = Height
.Left = Left
.Top = Top
.Caption = Caption_Text
End With
End Select
End Sub
I use this code to create a command button from my activex control, in the activex control!
My question is:
How can i know the exact name of the button which is clicked!
I know that the name of the command button should be "CMD" & countCMD + 1
but i must know the exact name when the button is clicked!
Hope you can help me! 
I think there is a way to capture the control's name when i clicked by API....
-
Mar 12th, 2005, 01:02 PM
#5
Re: Capture events from runtime controls
One problem with the code the way you've presented it here is that you lose your reference to a command button once you've added a second one since you are assigning them all to the global CMD variable. I don't understand why you do this???
-
Mar 12th, 2005, 05:55 PM
#6
Thread Starter
Hyperactive Member
Re: Capture events from runtime controls
How can i assign them in seperate variables?
Is there any chance to do it without using table variable?
-
Mar 12th, 2005, 06:35 PM
#7
-
Mar 12th, 2005, 07:00 PM
#8
-
Mar 12th, 2005, 07:17 PM
#9
Thread Starter
Hyperactive Member
Re: Capture events from runtime controls
The code works and helped me a lot! Thank you Manavo11!
-
Mar 12th, 2005, 07:25 PM
#10
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|