How do you add a command button or form through code and then determine its location ?
:)
Printable View
How do you add a command button or form through code and then determine its location ?
:)
Very recently there have been at least two of this kind of qwestions, go search for them
And what do you mean with location?!?
If you have VB5 you can only create controls by loading control arrays. In VB6, you can create them from scratch.
actually i always search before i ask a question; and if there are two questions i have not found them or the right syntax for the search. If you don't want to help that is fine -- but what exactly was your point?
How do you create them from scratch in vb6?
I don't have VB6, so I don't know. i remember some one saying somthing like...
Controls.Add
OR
Toolbox.Add
As I said, i don't Really know. But it might be somthing like that. Try using that statement and then VB will give you the rest by guiding you with the ToolTipText and the
Combo boxes as you type.
i know there is a way to do it from scratch in VB6 but I forogt how. Could someone who has VB6 try the methods i listed before and tell me if they work?
No nothing no toolbox and controls doesn't work as far as my knowledge takes me which is typing it and seeing what the choices are as the tooltips appear :P
I can't see how to create a control under runtime, i have vb5 but i don't think it's even possible under vb6 or is it?
Bebe,
I hope this is not to late. Here's the code I use to create checkboxes during run time.
Private Sub cmdAddCheckBoxes_Click()
Dim i As Integer 'The number of checkboxes
'Add checkboxes
For i = 1 To 3
'Use the DB2_Name as the control key
'strChkBoxName = "chkBox" & Trim(Str(iWS_Row - 1))
strkeyname = "CheckBox"
Set AddChkBox = UserForm1.Controls.Add("Forms.CheckBox.1", strkeyname, True)
With AddChkBox
.Caption = Str(i)
.FontSize = 8
.Top = 6 + (18 * (i - 1))
.Width = 150
.Left = 12
.Height = 18
'Check worksheet to see if db2 field was selected
End With
' colCheckBoxes.Add strkeyname
Next i
End Sub
Code:Controls.Add "VB.CommandButton", "Command1"
Me!Command1.Move 0, 0
Me!Command1.Caption = "Command1"
Me!Command1.Visible = True
Or if you have VB5, use CreateWindowEx
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
Const WS_CHILD = &H40000000
Private Sub Form_Load()
retval = CreateWindowEx(0&, "Button", "Button1", WS_CHILD, 32, 32, 64, 64, Me.hwnd, 0, App.hInstance, ByVal 0&)
ShowWindow retval, 1
End Sub