Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Demonstrates how to add controls at run-time. Well...
Author:
Bryan King
E-mail:
Click to e-mail author
Submitted:
3/30/2002
Version:
VB5
Compatibility:
VB5, VB6
Category:
Forms
Views:
12445
Demonstrates how to add controls at run-time. Well commented.
Declarations:
'none
Code:
'this demonstration assumes the following: 'add a CommandButton (Command1) to Form1 'and set the new button's Index property 'to 0 (zero), its Top property to 0 (zero), 'and its Left property to 120 'please do not hesitate to email me with 'questions regarding this snippet 'bryanwks@hotmail.com 'add this code to Form1 Private Sub Command1_Click(Index As Integer) 'this code simply demonstrates that each new CommandButton 'can execute its own event based on its Index property Select Case Command1(Index) Case Command1(0) 'the original CommandButton Unload Me Case Command1(1) MsgBox "You pressed Command 1" 'the first new button created Case Command1(2) MsgBox "You pressed Command 2" 'the second new button created Case Command1(3) Unload Me 'the third new button created Case Command1(4) MsgBox "You pressed Command 4" 'the fourth new button created Case Command1(5) MsgBox "You pressed Command 5" 'the fifth new button created End Select End Sub Private Sub Form_Load() Dim iIdx As Integer 'this holds the index value of new buttons Dim t As Integer 'this holds the Top property value 'since the original button is at the top left corner of 'the form and its height property is set to default(495) 'we will place the first button under the original 'and the second button under the first and so on... 'this can be changed to suit your needs t = 495 'place the first new button under the original 'you can set the original button's Visible property 'to False if you don't want it to show at run-time 'you can't load or unload Command1(0) as it is the original button 'so we must start with Index number 1 For iIdx = 1 To 5 'cycle thru to create five new buttons Load Command1(iIdx) Command1(iIdx).Left = 120 Command1(iIdx).Top = t Command1(iIdx).Height = 495 Command1(iIdx).Caption = "Command " & (iIdx) Command1(iIdx).Visible = True t = t + 495 'this can be changed to suit your needs Next End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement