Hard Coding Licence String

Occasionally it is necessary to hard code a licence sting. An example would be if new viewers are created dynamically.

 

Public Class Form1
   Dim MiniatureViewers As New System.Collections.ArrayList
   Friend WithEvents tempThumbnailViewer As AxDicomObjects.AxDicomViewer
   Dim x As Integer = 75
   Dim y As Integer = 10
 Private Sub Make_Viewer(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       tempThumbnailViewer = New AxDicomObjects.AxDicomViewer

       Dim f As Reflection.FieldInfo
       f = GetType(System.Windows.Forms.AxHost).GetField("licenseKey", Reflection.BindingFlags.NonPublic Or _
          Reflection.BindingFlags.Instance)  
       f.SetValue(tempThumbnailViewer, "the first line in the DicomObjects.lic file")

       tempThumbnailViewer.Parent = TabPage1
       x = x + 55
       tempThumbnailViewer.Location = New System.Drawing.Point(x, y)
       tempThumbnailViewer.BackColour = System.Drawing.Color.Black
       tempThumbnailViewer.Size = New System.Drawing.Size(50, 50)

       tempThumbnailViewer.Images.ReadFile("c:\pad\ybr")

       MiniatureViewers.Add(tempThumbnailViewer)
 End Sub
 Private Sub Remove_Viewers(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
       For i As Integer = 0 To MiniatureViewers.Count - 1
           tempThumbnailViewer = MiniatureViewers(i)
           tempThumbnailViewer.Hide()
       Next

       For i As Integer = 0 To MiniatureViewers.Count - 1
           tempThumbnailViewer = MiniatureViewers(i)
           tempThumbnailViewer.Images.Clear()
           tempThumbnailViewer.Dispose()
           tempThumbnailViewer = Nothing

           Application.DoEvents()
           GC.Collect()
           Application.DoEvents()
       Next

       MiniatureViewers.Clear()

       Application.DoEvents()
       GC.Collect()
       Application.DoEvents()
       x = 75
  End Sub
End Class
Relevance: