I'm trying to learn how to add and move objects in VB6 through the code module. SO far i've figured out how to insert an object but have no idea how to change the position.

This is what i have so far:

Option Explicit
Private WithEvents cmdOk As CommandButton


Private Sub cmdOk_Click()
Unload Me
End Sub

Private Sub Form_Load()
Set cmdOk = Form1.Controls.AdD("VB.CommandButton", "CmdOK")
cmdOk.Visible = True
cmdOk.Caption = "OK"
End Sub

You have two options...

use the...
.Left
.Top
.Width
.Height

Properties or you could use the...

.Move

Method

Good Luck

cmdOk.move left,top,width,height
' or
    cmdOk.left=left
    cmdOk.top=top
    cmdOkwidth=width
    cmdOk.height=height

but if you want to move this control in anotehr form or module you must use public

I'm trying to learn how to add and move objects in VB6 through the code module. SO far i've figured out how to insert an object but have no idea how to change the position.

This is what i have so far:

Option Explicit
Private WithEvents cmdOk As CommandButton


Private Sub cmdOk_Click()
Unload Me
End Sub

Private Sub Form_Load()
Set cmdOk = Form1.Controls.AdD("VB.CommandButton", "CmdOK")
cmdOk.Visible = True
cmdOk.Caption = "OK"
End Sub

Thanks to both. Another question. what is the best way to center said object.

ctrl.left=(form1.scalewidth-ctrl.width)/2
ctrl.top=(form1.scaleheight-ctrl.height)/2

thank you omoridi

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.