ActiveX with VB
-
Hi ! I'm building an App using Visual Basic 6, where I would like to display many ActiveX controls. The number and types of ActiveX to display is not hard-coded in the App, but rather put in a text file that would be read during initialization of the App, thus allowing me to add/remove ActiveX controls without recompiling my App. My problem is I don't know how to use an ActiveX control in VB without registering it (Project->Component) and putting it into a form. I would like to register it during code execution and placing it into my form dynamically. Anyone knows how to do that ? Thank you for your help ! Jerome
-
Hi ! I'm building an App using Visual Basic 6, where I would like to display many ActiveX controls. The number and types of ActiveX to display is not hard-coded in the App, but rather put in a text file that would be read during initialization of the App, thus allowing me to add/remove ActiveX controls without recompiling my App. My problem is I don't know how to use an ActiveX control in VB without registering it (Project->Component) and putting it into a form. I would like to register it during code execution and placing it into my form dynamically. Anyone knows how to do that ? Thank you for your help ! Jerome
To simply put it, it's a whole heck of a lot easier to reference all the ActiveX controls (Project/Components...) you'll need and create them as needed. Also, if you use the package and desployment wizard it'll make sure the OCXs are included in your installation. I am not sure what it is exactly you are looking to do, but if you do reference the controls, you can use a control array along with the Load statement to create new indices at runtime. You don't have to use a control array. Reference the rich edit control in your project, Uncheck "Remove information about unused ActiveX Controls" from Project Properties/Make. And run the following code...
Dim MyControl As Control
Private Sub Form_Load()
Set MyControl = Me.Controls.Add("RICHTEXT.RichTextCtrl.1", _
"RichText1", Me)MyControl.Text = "I'm Dynamic!"
MyControl.Font.Bold = True
MyControl.Font.Italic = True
MyControl.Visible = TrueEnd Sub
Private Sub Form_Resize()
If IsObject(MyControl) Then _
MyControl.Move 0, 0, Me.ScaleWidth, Me.ScaleHeightEnd Sub
Private Sub Form_Unload(Cancel As Integer)
If IsObject(MyControl) Then Set MyControl = Nothing
End Sub
However, in doing this you'll need to know the ProgID for the ActiveX control. I generally, place the control on the form, save it, use the .frm file to get the class name, run it, and get an error message giving me the ProgID. You can also get it from the registry, but I'm lazy. :) If you don't register the control in the project you may have to deal with licensing info in your code. Most MS ActiveX controls require a license to be used. You could create one manually, but this becomes more of a pain than it's worth. Good luck... Jeremy L. Falcon "The One Who Said, 'The One Who Said...'"