Dynamically adding COM Viewer control to .NET application form

First of all, you need to have at least one Viewer control on the form before you can dynamically add other viewer controls. The OCXState contains all sorts of information and most important of all – the licensing information of the DicomViewer control. That’s why you have to have at least one viewer by design time on the form before you can add others on the fly. The following code demonstrates how to add a second DicomViewer on the fly:

private void button1_Click(object sender, EventArgs e)
    AxDicomObjects.EventArgsAxDicomViewer axDicomViewer2 = new AxDicomObjects.EventArgsAxDicomViewer();
    axDicomViewer2.Name = "axDicomViewer2";
    ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));

    axDicomViewer2.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axDicomViewer1.OcxState")));

    axDicomViewer2.Location = new System.Drawing.Point(17, 140);
    axDicomViewer2.Size = new System.Drawing.Size(242, 121);
    axDicomViewer2.TabIndex = 9;
    axDicomViewer2.MultiColumns = 2;