Click to See Complete Forum and Search --> : TextBox


hoa01206
August 16th, 2001, 04:52 PM
Hello,

Is there a way to do the following. Instead of draging a textbox control to a form during design time, can I do that from within the code.

I tried

dim x as textbox

load method

set x = new textbox.

Did not work... ANy Ideas??? Please let me know




Thanks
Hisham

John G Duffy
August 16th, 2001, 04:59 PM
Hee is a sample that will create a Command Button at run time. Easly changed to create a textbox

option Explicit

' Declare object variable as CommandButton.
private withevents cmdObject as CommandButton

private Sub Form_Load()
set cmdObject = frmCreate.Controls.Add("VB.CommandButton", "cmdOne")
cmdObject.Visible = true
cmdObject.Caption = "Dynamic Command Button"
cmdObject.Move 1000, 1000, 1000, 1000
End Sub

private Sub cmdObject_Click()
print "This is a dynamically added control"
End Sub

private Sub Form_Unload(Cancel as Integer)
' get rid of created control
me.Controls.Remove cmdObject

End Sub




John G

hoa01206
August 16th, 2001, 05:08 PM
Thanx a lot John. Worked fine.

Thanks
Hisham