can you insert/create frames, buttons and such like with code, whilst your running a program.
Printable View
can you insert/create frames, buttons and such like with code, whilst your running a program.
I think so,but i don't know how.
The way i do it if i have programs that need it to to draw the control or controls on the form, make them invisable and make them single element control array (just add a 0 to the index value)
Then you can
you can add the code for the buttons and such at design time easily then.Code:Load Button(new index no)
'and
unload Button(index of button to remove)
I don't think you can, but like the above person said if you know the largest amount of labels/buttons for example your gonna use on the app then you can use visible function.
Label1.visible = false
'and whenever you actually want it to show
label1.visible = true
If its a lot of labels, and you dont want to see all them cluttered at design time......you can also tell it what width and height to be at but would be a lot of code if a lot of controls. Hope that helpz.
Yes..this example is a button
Code:'VB6
' Remarks:
' Dynamically add a new button to the form. The
' item to add, a button in this case, must be a
' member of the VB object as displayed in the
' Object Browser. The second parameter is the
' the new control's name.
'------------------------------------------------------------
'on the form add 2 command buttons...cmdQuit and cmdRemove
'height of form 2600...width 4400..put buttons lower left
'buttons...height = 324...width = 1600
'
Set btnObj = Controls.Add("VB.CommandButton", "btnObj")
Private WithEvents picObj As CommandButton
'
With btnObj
.Visible = True
.Caption = "&Dynamically Added Button"
.Top = 100
.Left = 2222
.Width = 1600
.Height = 324
End With
End Sub
Private Sub btnObj_Click()
'
' Respond to the new button's Click event.
'
MsgBox "This button was added at run time!"
End Sub
Thats not what i said.
You only need one invisable button to load up and max of 32k buttons and each one you load up you can set the different propties.
They will all have the same code thou, but with an Index value added to each event
For Example
A Single Button has the following click Event:
While a Single Button in a control array has the following click Event:Code:Private Sub Command1_Click()
End Sub
So you have one button InvisibleCode:Private Sub Command1_Click(Index as Integer)
End Sub
If you want to load a button or two at run time then you do this:
If you do it with Frames only the Frame only the frame and not its contents will be cloned., but if you do it to each control within a frame then they will remain part of the frame when cloned.Code:Load Command1(1) 'This will make a new button with index of 1
Command1(1).left = X 'Need to setup up All differences
Command1(1).visible = true 'New controls will ALWAYS be invisable
An exception to think i think (don't quote me) is forms, if you load a copy of a form, all its controls get cloned aswell.
Nicer, nicely put. :D
If you are using an array of a control, you need a control with an index of 0.
If you just want to add a control then you don't need one present as the object can be created dynamically at run time.
thank you all for your input.
i didnt want to start an argument but i think ill use joes method.
thanks again ...
will it work in vb5 as your rem said vb6
I'm not sure on that one...some things I have documented as only VB6...this one I didn't but for some reason I think it is only vb6....not hard to test if you have vb5...if it doesn't work it's 6.
If it is 6 only and all you have is 5 do a search on dynamic and use Megatron as user name to search on. I've seen postings by him using vb5 to add controls dynamically.
My code is VB6 only.
Here is Megatron's for vb5
For VB5, you can create buttons at runtime. It just involves manually using the CreateWindowEx API.
__________________Code:Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const WS_CHILD = &H40000000
Private BTN As Long
Private Sub Form_Load()
BTN = CreateWindowEx(0, "Button", "Button1", WS_CHILD, 32, 32, 64, 64, hwnd, 0, App.hInstance, ByVal 0)
ShowWindow BTN, 1
End Sub
Megatron
[email protected]
Visual Basic 5 SP3
See the VBFE Library