Public Class Form1
    Inherits System.Windows.Forms.Form
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents btnOpen As System.Windows.Forms.Button
    Friend WithEvents btnClose As System.Windows.Forms.Button
    Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu

#Region " Windows Form 디자이너에서 생성한 코드 "

    Public Sub New()
        MyBase.New()

        '이 호출은 Windows Form 디자이너에 필요합니다.
        InitializeComponent()

        'InitializeComponent()를 호출한 다음에 초기화 작업을 추가하십시오.

    End Sub

    'Form은 Dispose를 재정의하여 구성 요소 목록을 정리합니다.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        MyBase.Dispose(disposing)
    End Sub

    '참고: 다음 프로시저는 Windows Form 디자이너에 필요합니다.
    'Windows Form 디자이너를 사용하여 수정할 수 있습니다.  
    '코드 편집기를 사용하여 수정하지 마십시오.
    Friend WithEvents btnPrintText As System.Windows.Forms.Button
    Friend WithEvents btnPrintBitmap As System.Windows.Forms.Button
    Friend WithEvents btnPrintSample As System.Windows.Forms.Button
    Friend WithEvents btnExit As System.Windows.Forms.Button
    Friend WithEvents btnPrintBarCode As System.Windows.Forms.Button
    Friend WithEvents txtIP As System.Windows.Forms.TextBox
    Private Sub InitializeComponent()
        Me.MainMenu1 = New System.Windows.Forms.MainMenu
        Me.Label1 = New System.Windows.Forms.Label
        Me.btnOpen = New System.Windows.Forms.Button
        Me.btnClose = New System.Windows.Forms.Button
        Me.btnPrintText = New System.Windows.Forms.Button
        Me.btnPrintBitmap = New System.Windows.Forms.Button
        Me.btnPrintBarCode = New System.Windows.Forms.Button
        Me.btnPrintSample = New System.Windows.Forms.Button
        Me.btnExit = New System.Windows.Forms.Button
        Me.txtIP = New System.Windows.Forms.TextBox
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(24, 32)
        Me.Label1.Size = New System.Drawing.Size(64, 16)
        Me.Label1.Text = "IP : "
        '
        'btnOpen
        '
        Me.btnOpen.Location = New System.Drawing.Point(120, 16)
        Me.btnOpen.Size = New System.Drawing.Size(88, 24)
        Me.btnOpen.Text = "Connect"
        '
        'btnClose
        '
        Me.btnClose.Location = New System.Drawing.Point(120, 48)
        Me.btnClose.Size = New System.Drawing.Size(88, 24)
        Me.btnClose.Text = "Disconnect"
        '
        'btnPrintText
        '
        Me.btnPrintText.Location = New System.Drawing.Point(24, 88)
        Me.btnPrintText.Size = New System.Drawing.Size(184, 24)
        Me.btnPrintText.Text = "Print Text"
        '
        'btnPrintBitmap
        '
        Me.btnPrintBitmap.Location = New System.Drawing.Point(24, 118)
        Me.btnPrintBitmap.Size = New System.Drawing.Size(184, 24)
        Me.btnPrintBitmap.Text = "Print Bitmap"
        '
        'btnPrintBarCode
        '
        Me.btnPrintBarCode.Location = New System.Drawing.Point(24, 148)
        Me.btnPrintBarCode.Size = New System.Drawing.Size(184, 24)
        Me.btnPrintBarCode.Text = "Print Barcode"
        '
        'btnPrintSample
        '
        Me.btnPrintSample.Location = New System.Drawing.Point(24, 178)
        Me.btnPrintSample.Size = New System.Drawing.Size(184, 24)
        Me.btnPrintSample.Text = "Print TTF"
        '
        'btnExit
        '
        Me.btnExit.Location = New System.Drawing.Point(24, 208)
        Me.btnExit.Size = New System.Drawing.Size(184, 32)
        Me.btnExit.Text = "Exit"
        '
        'txtIP
        '
        Me.txtIP.Location = New System.Drawing.Point(24, 48)
        Me.txtIP.Size = New System.Drawing.Size(90, 21)
        Me.txtIP.Text = ""
        '
        'Form1
        '
        Me.ClientSize = New System.Drawing.Size(226, 270)
        Me.Controls.Add(Me.txtIP)
        Me.Controls.Add(Me.btnExit)
        Me.Controls.Add(Me.btnPrintSample)
        Me.Controls.Add(Me.btnPrintBarCode)
        Me.Controls.Add(Me.btnPrintBitmap)
        Me.Controls.Add(Me.btnPrintText)
        Me.Controls.Add(Me.btnClose)
        Me.Controls.Add(Me.btnOpen)
        Me.Controls.Add(Me.Label1)
        Me.Menu = Me.MainMenu1
        Me.Text = "Form1"

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtIP.Text = "192.168.10.200"

        btnClose.Enabled = False
        btnPrintText.Enabled = False
        btnPrintBitmap.Enabled = False
        btnPrintBarCode.Enabled = False
        btnPrintSample.Enabled = False

    End Sub

    Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
        Dim lResult As Long
        lResult = LKPrint.OpenPort(txtIP.Text, 9100)
        If (lResult <> 0) Then
            MessageBox.Show("Open Port Failed")
            Exit Sub
        End If

        btnOpen.Enabled = False
        btnClose.Enabled = True
        btnPrintText.Enabled = True
        btnPrintBitmap.Enabled = True
        btnPrintBarCode.Enabled = True
        btnPrintSample.Enabled = True
        btnExit.Enabled = False

    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Dim lResult As Long
        lResult = LKPrint.ClosePort()

        If (lResult <> 0) Then
            MessageBox.Show("Close Port Failed")
            Exit Sub
        End If

        btnOpen.Enabled = True
        btnClose.Enabled = False
        btnPrintText.Enabled = False
        btnPrintBitmap.Enabled = False
        btnPrintBarCode.Enabled = False
        btnPrintSample.Enabled = False
        btnExit.Enabled = True

    End Sub

    Private Sub btnPrintText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintText.Click
        Dim lResult As Long
        Dim ErrMsg As String

        lResult = LKPrint.PrinterCheck()

        Select Case lResult
            Case -1 ' Bluetooth Write Fail. Please Check Connection.
                MessageBox.Show("Write Error")
                Return
            Case -2
                MessageBox.Show("Fail to Read Printer Status")
                Return
        End Select

        lResult = LKPrint.status()
        If (lResult <> LKPrint.LK_STS_NORMAL) Then
            ErrMsg = String.Format("Printer Status get Error ErrorCode = %d", lResult)
            MessageBox.Show(ErrMsg)
            Return
        End If

        LKPrint.PrintText("Receipt" + vbCrLf + vbCrLf + vbCrLf, LKPrint.LK_ALIGNMENT_CENTER, LKPrint.LK_FNT_DEFAULT, LKPrint.LK_TXT_2WIDTH Or LKPrint.LK_TXT_1HEIGHT)
        LKPrint.PrintText("TEL (123)-456-7890" + vbCrLf, LKPrint.LK_ALIGNMENT_RIGHT, LKPrint.LK_FNT_DEFAULT, LKPrint.LK_TXT_1WIDTH Or LKPrint.LK_TXT_1HEIGHT)
        LKPrint.PrintText("Thank you for coming to our shop!" + vbCrLf, LKPrint.LK_ALIGNMENT_CENTER, LKPrint.LK_FNT_DEFAULT, LKPrint.LK_TXT_1WIDTH Or LKPrint.LK_TXT_1HEIGHT)
        LKPrint.PrintText("Chicken                   $10.00" + vbCrLf, LKPrint.LK_ALIGNMENT_LEFT, LKPrint.LK_FNT_DEFAULT, LKPrint.LK_TXT_1WIDTH Or LKPrint.LK_TXT_1HEIGHT)
        LKPrint.PrintText("Hamburger                 $20.00" + vbCrLf, LKPrint.LK_ALIGNMENT_LEFT, LKPrint.LK_FNT_DEFAULT, LKPrint.LK_TXT_1WIDTH Or LKPrint.LK_TXT_1HEIGHT)
        LKPrint.PrintText("Pizza                     $30.00" + vbCrLf, LKPrint.LK_ALIGNMENT_LEFT, LKPrint.LK_FNT_DEFAULT, LKPrint.LK_TXT_1WIDTH Or LKPrint.LK_TXT_1HEIGHT)
        LKPrint.PrintText("Lemons                    $40.00" + vbCrLf, LKPrint.LK_ALIGNMENT_LEFT, LKPrint.LK_FNT_DEFAULT, LKPrint.LK_TXT_1WIDTH Or LKPrint.LK_TXT_1HEIGHT)
        LKPrint.PrintText("Drink                     $50.00" + vbCrLf + vbCrLf, LKPrint.LK_ALIGNMENT_LEFT, LKPrint.LK_FNT_DEFAULT, LKPrint.LK_TXT_1WIDTH Or LKPrint.LK_TXT_1HEIGHT)
        LKPrint.PrintText("Excluded tax             $150.00" + vbCrLf, LKPrint.LK_ALIGNMENT_LEFT, LKPrint.LK_FNT_DEFAULT, LKPrint.LK_TXT_1WIDTH Or LKPrint.LK_TXT_1HEIGHT)
        LKPrint.PrintText("Tax(5%)                    $7.50" + vbCrLf, LKPrint.LK_ALIGNMENT_LEFT, LKPrint.LK_FNT_UNDERLINE, LKPrint.LK_TXT_1WIDTH Or LKPrint.LK_TXT_1HEIGHT)
        LKPrint.PrintText("Total    $157.50" + vbCrLf + vbCrLf, LKPrint.LK_ALIGNMENT_LEFT, LKPrint.LK_FNT_DEFAULT, LKPrint.LK_TXT_2WIDTH Or LKPrint.LK_TXT_1HEIGHT)
        LKPrint.PrintText("Payment                  $200.00" + vbCrLf, LKPrint.LK_ALIGNMENT_LEFT, LKPrint.LK_FNT_DEFAULT, LKPrint.LK_TXT_1WIDTH Or LKPrint.LK_TXT_1HEIGHT)
        LKPrint.PrintText("Change                    $42.50" + vbCrLf + vbCrLf, LKPrint.LK_ALIGNMENT_LEFT, LKPrint.LK_FNT_DEFAULT, LKPrint.LK_TXT_1WIDTH Or LKPrint.LK_TXT_1HEIGHT)

    End Sub

    Private Sub btnPrintBitmap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintBitmap.Click
        Dim lResult As Long
        Dim ErrMsg As String
        Dim strFileName As String = Nothing

        lResult = LKPrint.PrinterCheck()

        Select Case lResult
            Case -1 ' Bluetooth Write Fail. Please Check Connection.
                MessageBox.Show("Write Error")
                Return
            Case -2
                MessageBox.Show("Fail to Read Printer Status")
                Return
        End Select

        lResult = LKPrint.status()
        If (lResult <> LKPrint.LK_STS_NORMAL) Then
            ErrMsg = String.Format("Printer Status get Error ErrorCode = %d", lResult)
            MessageBox.Show(ErrMsg)
            Return
        End If

        Dim openFileDialog1 As New OpenFileDialog

        openFileDialog1.InitialDirectory = ".\"
        openFileDialog1.Filter = "Bitmap files (*.bmp)|*.bmp|All files (*.*)|*.*"
        openFileDialog1.FilterIndex = 1

        If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
            Try
                strFileName = openFileDialog1.FileName
                If (strFileName.Length()) Then
                    LKPrint.PrintBitmap(strFileName, LKPrint.LK_ALIGNMENT_CENTER, 0)
                End If
            Catch Ex As Exception
                MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
            End Try
        End If
    End Sub

    Private Sub btnPrintBarCode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintBarCode.Click
        Dim lResult As Long
        Dim ErrMsg As String
        Dim ESC As String

        ESC = Chr(&H1B)

        lResult = LKPrint.PrinterCheck()

        Select Case lResult
            Case -1 ' Bluetooth Write Fail. Please Check Connection.
                MessageBox.Show("Write Error")
                Return
            Case -2
                MessageBox.Show("Fail to Read Printer Status")
                Return
        End Select

        lResult = LKPrint.status()
        If (lResult <> LKPrint.LK_STS_NORMAL) Then
            ErrMsg = String.Format("Printer Status get Error ErrorCode = %d", lResult)
            MessageBox.Show(ErrMsg)
            Return
        End If

        PrintNormal("-----start of barcode-----" + vbCrLf)
        PrintNormal("3 of 9 barcode" + vbCrLf)
        PrintBarCode("1234567890", LKPrint.LK_BCS_Code39, 40, 384, LKPrint.LK_ALIGNMENT_CENTER, LKPrint.LK_HRI_TEXT_BELOW)
        PrintNormal("Code 93 barcode" + vbCrLf)
        PrintBarCode("0123498765", LKPrint.LK_BCS_Code93, 40, 384, LKPrint.LK_ALIGNMENT_CENTER, LKPrint.LK_HRI_TEXT_BELOW)
        PrintNormal("Interleaved 2 of 5 barcode" + vbCrLf)
        PrintBarCode("0987654321", LKPrint.LK_BCS_ITF, 40, 384, LKPrint.LK_ALIGNMENT_CENTER, LKPrint.LK_HRI_TEXT_BELOW)
        PrintNormal("Code 128 A barcode" + vbCrLf)
        PrintBarCode("{ACODE 128", LKPrint.LK_BCS_Code128, 40, 384, LKPrint.LK_ALIGNMENT_CENTER, LKPrint.LK_HRI_TEXT_BELOW)
        PrintNormal("Code 128 B barcode" + vbCrLf)
        PrintBarCode("{BCode 128", LKPrint.LK_BCS_Code128, 40, 384, LKPrint.LK_ALIGNMENT_CENTER, LKPrint.LK_HRI_TEXT_BELOW)
        PrintNormal("Code 128 C barcode" + vbCrLf)
        PrintBarCode("{C12345", LKPrint.LK_BCS_Code128, 40, 384, LKPrint.LK_ALIGNMENT_CENTER, LKPrint.LK_HRI_TEXT_BELOW)
        PrintNormal("Codabar barcode" + vbCrLf)
        PrintBarCode("A1029384756A", LKPrint.LK_BCS_Codabar, 40, 384, LKPrint.LK_ALIGNMENT_CENTER, LKPrint.LK_HRI_TEXT_BELOW)

        PrintNormal("-----end of barcode-----" + vbCrLf)

        PrintNormal(ESC + "|fP")

    End Sub

    Private Sub btnPrintSample_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintSample.Click
        Dim lResult As Long
        Dim ErrMsg As String
        Dim BarData As String = "0123456789"
        Dim ESC As String

        ESC = Chr(&H1B)

        lResult = LKPrint.PrinterCheck()

        Select Case lResult
            Case -1 ' Bluetooth Write Fail. Please Check Connection.
                MessageBox.Show("Write Error")
                Return
            Case -2
                MessageBox.Show("Fail to Read Printer Status")
                Return
        End Select

        lResult = LKPrint.status()
        If (lResult <> LKPrint.LK_STS_NORMAL) Then
            ErrMsg = String.Format("Printer Status get Error ErrorCode = %d", lResult)
            MessageBox.Show(ErrMsg)
            Return
        End If

        LKPrint.PrintNormal("----True-Type Font Printing.----" + vbCrLf)
        LKPrint.PrintNormal("Print Normal(24x24)" + vbCrLf)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H0, 24, 2)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H5, 24, 2)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H6, 24, 2)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H8, 24, 2)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H88, 24, 2)
        LKPrint.PrintNormal("Print Italic(24x24)" + vbCrLf)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H10, 24, 2)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H15, 24, 2)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H16, 24, 2)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H18, 24, 2)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H98, 24, 2)
        LKPrint.PrintNormal("Print Underline(24x24)" + vbCrLf)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H20, 24, 2)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H25, 24, 2)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H26, 24, 2)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H28, 24, 2)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &HA8, 24, 2)

        LKPrint.PrintNormal("Print Normal(28x28)" + vbCrLf)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H0, 28, 1)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H5, 28, 1)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H6, 28, 1)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H8, 28, 1)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H88, 28, 1)
        LKPrint.PrintNormal("Print Italic(28x28)" + vbCrLf)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H10, 28, 1)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H15, 28, 1)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H16, 28, 1)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H18, 28, 1)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H98, 28, 1)
        LKPrint.PrintNormal("Print Underline(28x28)" + vbCrLf)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H20, 28, 1)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H25, 28, 1)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H26, 28, 1)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H28, 28, 1)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &HA8, 28, 1)

        LKPrint.PrintNormal("Print Normal(32x32)" + vbCrLf)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H0, 32, 0)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H5, 32, 0)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H6, 32, 0)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H8, 32, 0)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H88, 32, 0)
        LKPrint.PrintNormal("Print Italic(32x32)" + vbCrLf)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H10, 32, 0)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H15, 32, 0)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H16, 32, 0)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H18, 32, 0)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H98, 32, 0)
        LKPrint.PrintNormal("Print Underline(32x32)" + vbCrLf)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H20, 28, 0)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H25, 28, 0)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H26, 28, 0)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &H28, 28, 0)
        LKPrint.PrintText2Image("Tahoma Font", "Tahoma", &HA8, 28, 0)

        LKPrint.PrintNormal("--True-Type Font Printing End.--" + vbCrLf)


        LKPrint.PrintNormal(ESC + "|fP")


    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Dispose(True)
    End Sub
End Class
