ImageViewerControl needs to be on a UserControl before Initialize is called

Since we cannot see the ImageViewerComponent in toolbox to directly add it into the designer, I am trying to explicitly add the ImageViewerControl into our panel

But I am getting error:

ImageViewerControl needs to be on a UserControl before Initialize is called

here is how I am adding it explicitly

Private Sub InitMilestoneComponents()

Const FunctionName As String = "clsMilestoneWrapper.Init"

Try

  Dim selectedCamera = clsMilestoneShared.EngineManagerConnectToServer(Me.mParentForm, 1, 12, 1)

  Me.mParentForm.SplitContainer1.Panel1.Controls.Add(LiveMilestone)

  Me.mParentForm.SplitContainer1.Panel2.Controls.Add(EventMilestone)

  LiveMilestone.CameraFQID = selectedCamera.FQID

  EventMilestone.CameraFQID = selectedCamera.FQID

  LiveMilestone.Initialize()

  EventMilestone.Initialize()

  LiveMilestone.Connect()

  EventMilestone.Connect()

  MilestoneImageViewerEnableEvents(LiveMilestone)

  MilestoneImageViewerEnableEvents(EventMilestone)

  MilestoneImageViewerSetHandlers(LiveMilestone)

  MilestoneImageViewerSetHandlers(EventMilestone)

Catch ex As Exception

  dbg.LogError(FunctionName, "Error - " & ex.Message)

End Try

End Sub

LiveMilestone and EventMilestone is generated as

  mLiveClientControl = ClientControl.Instance

  mEventClientControl = ClientControl.Instance

  LiveMilestone = mLiveClientControl.GenerateImageViewerControl()

EventMilestone = mLiveClientControl.GenerateImageViewerControl()

Just in case, I tried using ImageViewerWpfControl too

If you do this after InitializeComponent() there should be a UI and we cannot see why you would get the error you observe.

I suggest you look at a sample (I recommend VideoViewer) and see the order of things in that sample. Now that sample was changed to use WPF, and that is the general recommendation. But if you want this sample in WinForms you will need to navigate to the 2023R2 version of the samples.

https://doc.developer.milestonesys.com/html/index.html?base=samples/componentsamples/videoviewer/readme.html&tree=tree_2.html

https://github.com/milestonesys

The ImageViewerWpfControl should be usable in the XAML designer directly.