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
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
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.