I'm developing an app here that uses ActiveX controls to connect to industrial cameras over Ethernet. I want to be able to dynamically create those controls at runtime based on how many cameras are configured, rather than take the easy way out and put a fixed amount of controls on the form at design. Makes it more flexible.
At the moment the way I am trying to do it is adding instances of the control into a collection with their individual properties set, then for each-ing through the collection and adding the controls to the form. Now, this is where I get the problems. I can access the properties of the control, like height, name, and so on, but any of the properties or methods from the control itself are not accessible at all. I can't reference them by name (like "CameraControl. RemoteHost = "blah"); it causes a syntax error because the control isn't there yet. I can't do it through Me.Controls.Ite ms("name").Remo teHost because that property is not a property of the control class. I tried setting these properties before adding the item to the collection (by doing cntDVTSID.Remot eHost = "127.0.0.1" ), but then I get an error at runtime: Exception of type System.Windows. Forms.AxHost+In validActiveXSta teException' was thrown.
Here is the code I am using, if it helps:
Anyone have some ideas? I'm really starting to miss control arrays from VB6 :)
edit: fixed code
At the moment the way I am trying to do it is adding instances of the control into a collection with their individual properties set, then for each-ing through the collection and adding the controls to the form. Now, this is where I get the problems. I can access the properties of the control, like height, name, and so on, but any of the properties or methods from the control itself are not accessible at all. I can't reference them by name (like "CameraControl. RemoteHost = "blah"); it causes a syntax error because the control isn't there yet. I can't do it through Me.Controls.Ite ms("name").Remo teHost because that property is not a property of the control class. I tried setting these properties before adding the item to the collection (by doing cntDVTSID.Remot eHost = "127.0.0.1" ), but then I get an error at runtime: Exception of type System.Windows. Forms.AxHost+In validActiveXSta teException' was thrown.
Here is the code I am using, if it helps:
Code:
Dim i As Integer i = 0 For Each clsCamera In colCameras Dim cntDVTSID As New AxAxSID.AxDVTSID cntDVTSID.Visible = True cntDVTSID.Top = 29 * i cntDVTSID.Left = 149 * i cntDVTSID.Name = clsCamera.Name i += 1 colCameraControls.Add(cntDVTSID, cntDVTSID.Name) lstCameras.Items.Add(clsCamera.Name) Next 'Add the controls to the form For Each cntDVTSID As AxAxSID.AxDVTSID In colCameraControls Me.Controls.Add(cntDVTSID) Next
edit: fixed code