On button clicked create label in form7? It is possible in visual basic 6.0
Hello, I want to create a command that when the button is clicked creates a lable down the last label in form7. It's possible? If yes, how
Thanks
1 Attachment(s)
Re: On button clicked create label in form7? It is possible in visual basic 6.0
dear,
You can do this with "load".
Ihave don this in an example form moving picture.
see attachment.
br,
Re: On button clicked create label in form7? It is possible in visual basic 6.0
Well, that's nice, ggeu, but it does not create a label.
There are two ways of dynamically adding controls. One is like in ggeu's example performed with Load. That assumes that you have a control array, in your case an array of labels, where you can use
Load Label(n) to create a further instance of this label.
If you have not, you use
Code:
dim lblnew as label
set lblnew = Form.Controls.Add("VB.Label", "labelname")
this adds a completely new label to your controls. You have to position and resize it and make it visible, though.
Re: On button clicked create label in form7? It is possible in visual basic 6.0
Can you code it like ggeu please, since, I tried doing it didn't work. Also would be nicer if automatically adds a name instead of I choosing it.
Example, I have buttn1 so, when Is clicked I want to automatically appear button was clicked (date and time)
That's exactly what I want. Create a label or anything where appears when the button was clicked, and to make it possible to click it more than once.
I know it can be a lot for free, but I really need it
THANKS
Re: On button clicked create label in form7? It is possible in visual basic 6.0
What should happen if you click the button more than once? Should another label appear? Wouldn't mak much sense. You just put the date and time to the existing label. The creation of the new label only happens once then. With the .Move you can move it anywhere on the form.
The name of the label you supply in the .Add statement is irrelevant. You can't use it in your program anyway. Rather you have to access this label always through the Private declared lbl variable.
Code:
Private lbl As Label
Private Sub btnShow_Click()
If lbl Is Nothing Then
Set lbl = Controls.Add("VB.Label", "lblTime")
With lbl
.Move 100, 100
.Visible = True
'set more properties if necessary
End With
End If
lbl.Caption = Time
End Sub