470,849 Members | 1,211 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

(VB.NET) Accessing ActiveX controls created at runtime

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.Items("name").RemoteHost 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.RemoteHost = "127.0.0.1"), but then I get an error at runtime: Exception of type System.Windows.Forms.AxHost+InvalidActiveXStateExc eption' was thrown.

Here is the code I am using, if it helps:
Expand|Select|Wrap|Line Numbers
  1. Dim i As Integer
  2. i = 0
  3.  
  4. For Each clsCamera In colCameras
  5.    Dim cntDVTSID As New AxAxSID.AxDVTSID
  6.    cntDVTSID.Visible = True
  7.    cntDVTSID.Top = 29 * i
  8.    cntDVTSID.Left = 149 * i
  9.    cntDVTSID.Name = clsCamera.Name
  10.    i += 1
  11.    colCameraControls.Add(cntDVTSID, cntDVTSID.Name)
  12.    lstCameras.Items.Add(clsCamera.Name)
  13. Next
  14.  
  15. 'Add the controls to the form
  16. For Each cntDVTSID As AxAxSID.AxDVTSID In colCameraControls
  17.    Me.Controls.Add(cntDVTSID)
  18. Next
  19.  
Anyone have some ideas? I'm really starting to miss control arrays from VB6 :)

edit: fixed code
Jul 2 '08 #1
0 1324

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Fie Fie Niles | last post: by
reply views Thread by Dan | last post: by
reply views Thread by shawnn | last post: by
7 posts views Thread by Jarod_24 | last post: by
4 posts views Thread by Wilfried Mestdagh | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.