Imports System.ComponentModel
Imports System.Drawing
Imports System.windows.forms

Public Class Form1
  Inherits System.Windows.Forms.Form
  Private Spl As Spooler
  Public Sub New()
    MyBase.New()
    Form1 = Me
    'This call is required by the Win Form Designer.
    InitializeComponent()
    'TODO: Add any initialization after the InitializeComponent() call
  End Sub

#Region " Windows Form Designer generated code "

  'Required by the Windows Form Designer
  Private components As System.ComponentModel.Container
  Private WithEvents btGetSpooler As System.Windows.Forms.Button
  Private WithEvents Print As System.Windows.Forms.Button
  Private WithEvents TextBox1 As System.Windows.Forms.TextBox

  Dim WithEvents Form1 As System.Windows.Forms.Form

  'NOTE: The following procedure is required by the Windows Form Designer
  'It can be modified using the Windows Form Designer.  
  'Do not modify it using the code editor.
  Private Sub InitializeComponent()
    Me.btGetSpooler = New System.Windows.Forms.Button()
    Me.TextBox1 = New System.Windows.Forms.TextBox()
    Me.Print = New System.Windows.Forms.Button()
    Me.SuspendLayout()
    '
    'btGetSpooler
    '
    Me.btGetSpooler.Location = New System.Drawing.Point(72, 72)
    Me.btGetSpooler.Name = "btGetSpooler"
    Me.btGetSpooler.Size = New System.Drawing.Size(104, 32)
    Me.btGetSpooler.TabIndex = 2
    Me.btGetSpooler.Text = "Get spooler"
    '
    'TextBox1
    '
    Me.TextBox1.Location = New System.Drawing.Point(24, 40)
    Me.TextBox1.Name = "TextBox1"
    Me.TextBox1.Size = New System.Drawing.Size(200, 20)
    Me.TextBox1.TabIndex = 0
    Me.TextBox1.Text = ""
    '
    'Print
    '
    Me.Print.Location = New System.Drawing.Point(72, 120)
    Me.Print.Name = "Print"
    Me.Print.Size = New System.Drawing.Size(104, 32)
    Me.Print.TabIndex = 1
    Me.Print.Text = "Print"
    '
    'Form1
    '
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(292, 273)
    Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btGetSpooler, Me.Print, Me.TextBox1})
    Me.Name = "Form1"
    Me.Text = "Spooler demo"
    Me.ResumeLayout(False)

  End Sub

#End Region
  '--------
  Private Sub ErrorBox(ByVal mesg As String)
    MessageBox.Show(mesg, "Spooler Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
  End Sub
  '------
  Private Sub btGetSpooler_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btGetSpooler.Click
    Try
      Spl = Spooler.getSpooler
      TextBox1.Text = "Got spooler"
    Catch ex As Exception
      ErrorBox("Spooler already allocated")
    End Try
  End Sub

  Private Sub Print_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Print.Click
    Try
      Spl.Print("Hi there")
    Catch ex As Exception
      ErrorBox("No spooler allocated")
    End Try
  End Sub
End Class
