|
-
Apr 22nd, 2006, 08:00 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Make new forms and buttons and stuff in the program
Is there a way to make new forms and buttons when the programs running?
-
Apr 22nd, 2006, 10:22 AM
#2
Hyperactive Member
Re: Make new forms and buttons and stuff in the program
Maybe this link will help you. The problem is more or less the same like yours. Try to read this thread
http://www.vbforums.com/showthread.p...create+control
-
Apr 22nd, 2006, 10:44 AM
#3
Re: Make new forms and buttons and stuff in the program
@Bernard: Well that link for a different programming language, so i'm not sure that's going to help.
@Ahpro: Yes it is possible, what are you trying to achieve?
-
Apr 22nd, 2006, 01:08 PM
#4
Thread Starter
Addicted Member
Re: Make new forms and buttons and stuff in the program
there's actually another question coming with this aswell. say i want it to create a new label when i press a button, how would i 1. create the label and 2. make it have the same name as th elast label just the number on the end is the last one +1 so i don't end up with 2 or more having the same name.
-
Apr 22nd, 2006, 01:41 PM
#5
Hyperactive Member
Re: Make new forms and buttons and stuff in the program
I found a thread on how to create a new command button at runtime. Just go to the link below
http://www.vbforums.com/showthread.php?t=342054
Maybe this is the answer to your question. If it is so, please rate
VB Code:
Option Explicit
Dim WithEvents testLabel As Label
Private Sub Command1_Click()
Set testLabel = Form1.Controls.Add("VB.label", "newLabel")
'Set the properties of the new label
With testLabel
.Left = 1000
.Top = 1000
.Width = 2000
.Height = 500
.Caption = "Hello this is a new label!"
.Visible = True
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set testLabel = Nothing 'clear the memory
End Sub
-
Apr 22nd, 2006, 02:14 PM
#6
Addicted Member
Re: Make new forms and buttons and stuff in the program
there's actually another question coming with this aswell. say i want it to create a new label when i press a button, how would i 1. create the label and 2. make it have the same name as th elast label just the number on the end is the last one +1 so i don't end up with 2 or more having the same name.
VB Code:
Option Explicit
Dim WithEvents lbl As Label
Dim i As Integer
Private Sub Command1_Click()
i = i + 1
Set lbl = Form1.Controls.Add("VB.Label", "lblTest" & i)
With lbl
.Caption = "lblTest" & i
.Visible = True
.Top = i * 500
'Set the Left Position Etc.
End With
End Sub
Private Sub Form_Load()
i = -1
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set lbl = Nothing
End Sub
if i helped then please rate my post
-
Apr 22nd, 2006, 02:39 PM
#7
Thread Starter
Addicted Member
Re: Make new forms and buttons and stuff in the program
you're both stars, thanks a lot. i'll rate both of you well.
-
Apr 22nd, 2006, 02:42 PM
#8
Re: Make new forms and buttons and stuff in the program
In your situation (and most others too) it's best to have a control already on the form and just load another member of the array.
Place a label on the form (name it lblText) and set Index = 0, then:
VB Code:
Private Sub Command1_Click()
Load lblText(lblText.UBound + 1)
With lblText(lblText.UBound)
.Caption = "Hello"
.Visible = True
End With
End Sub
' Any events for this new label can be dealt with in the usual way
Private Sub lblText_Click(Index As Integer)
MsgBox "Click on Label: " & Index
End Sub
' Make sure you unload all but the last member of the array upon form unload
Private Sub Form_Unload(Cancel As Integer)
Dim N As Integer
If lblText.UBound > 0 Then
For N = lblText.UBound To lblText.LBound + 1
Unload lblText(N)
Next N
End If
End Sub
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
|