Option Strict On
Public Class MainForm
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Setup the layout of all 16 cameras at run time
Me.Width = Screen.PrimaryScreen.WorkingArea.Width
BeginCameraLayout()
End Sub
Private Sub BeginCameraLayout()
Dim screens As Integer
Dim count As Integer = 1
Dim camWidth As Integer = CInt(Screen.PrimaryScreen.WorkingArea.Width / 4)
For screens = 1 To 16
'This adds the necessary controls to the camera forms
Dim liveStatusLabel As New Label
Dim f As New Form
f.Controls.Add(liveStatusLabel)
'Format the new form's properties before displaying
f.Width = CInt(Screen.PrimaryScreen.WorkingArea.Width / 4)
f.Height = CInt((Screen.PrimaryScreen.WorkingArea.Height - Me.Height) / 4)
f.ShowInTaskbar = False
f.ShowIcon = False
f.ControlBox = False
f.Text = "Camera " & screens
f.MinimizeBox = False
f.Show()
f.Controls.Add(AddVideoScreen(screens)) 'Call to create the ActiveX control
Select Case screens
Case 1, 2, 3
f.Top = Me.Height
f.Left = (camWidth * count) - camWidth
count += 1
Case 4
f.Top = Me.Height
f.Left = (camWidth * count) - camWidth
count = 1
Case 5, 6, 7
f.Top = Me.Height + f.Height
f.Left = (camWidth * count) - camWidth
count += 1
Case 8
f.Top = Me.Height + f.Height
f.Left = (camWidth * count) - camWidth
count = 1
Case 9, 10, 11
f.Top = Me.Height + f.Height + f.Height
f.Left = (camWidth * count) - camWidth
count += 1
Case 12
f.Top = Me.Height + f.Height + f.Height
f.Left = (camWidth * count) - camWidth
count = 1
Case 13, 14, 15
f.Top = Me.Height + f.Height + f.Height + f.Height
f.Left = (camWidth * count) - camWidth
count += 1
Case 16
f.Top = Me.Height + f.Height + f.Height + f.Height
f.Left = (camWidth * count) - camWidth
End Select
Next
End Sub
Private Function AddVideoScreen(ByVal screen As Integer) As AxVIDEOCONTROLLib.AxVideoControl
Dim vcLive As New AxVIDEOCONTROLLib.AxVideoControl
vcLive.Dock = DockStyle.Fill
vcLive.DLLPath = Application.StartupPath & "\TL4516UL.dll"
vcLive.UserName = "live"
vcLive.Password = "live"
vcLive.IPAddress = "100.100.100.100"
vcLive.Port = 53705
vcLive.CameraID = screen
vcLive.Connect()
AddHandler vcLive.Status, New AxVIDEOCONTROLLib._DVideoControlEvents_StatusEventHandler(AddressOf vcLive_Status)
Return vcLive
End Function
Private Sub vcLive_Status(ByVal sender As Object, ByVal e As AxVIDEOCONTROLLib._DVideoControlEvents_StatusEvent)
If ((e.strMessage = "Status:Connection Established") OrElse e.strMessage.Contains("Error")) Then
If (e.strMessage = "Status:Connection Established") Then
f.vcLive.PlayLive() 'This line throws error. 'f' is not declared
End If
End If
End Sub
End Class