Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.IO.Ports
Imports System.Text.RegularExpressions
Imports VB_CPCL.Printer

Public Class Form1
    Inherits Form
    Private printer As DemPrinter = Nothing
    Private imagePath As String
    Private result As Integer

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnTest.Click
        printer = Nothing
        If printer Is Nothing Then
            printer = New DemPrinter("HM-A300")
            If printer Is Nothing Then
                MessageBox.Show("Creator Model Failed，INVALID MODEL!")
                Return
            End If
        Else
            printer.Model = "HM-A300"
        End If
        If Constants.E_SUCCESS = printer.PortOpen("USB") Then
            MessageBox.Show("Connect Succeed")

            'Set Size
            result = printer.AddLabel(0, 1000, 1)

            'Set Text Underline  and Bold
            result = printer.SetTextUnderline(1)
            result = printer.SetTextBold(2)
            result = printer.AddText(Define.ROTATE_NONE, 4, 7, 8, 0, "SetTextUnderline  TextBold")

            'normal Text
            result = printer.SetTextUnderline(0)
            result = printer.SetTextBold(0)
            result = printer.AddText(Define.ROTATE_NONE, 0, 0, 8, 40, "NORMAL TEXT")

            result = printer.AddBarCodeText(1, 2, 0, 0)

            'CODE 128
            result = printer.AddBarCode(Define.ROTATE_NONE, Define.BARCODE_128, 2, 2, 50, 8, 72, "CODE128")

            ''CODE 39
            result = printer.AddBarCode(Define.ROTATE_NONE, Define.BARCODE_39, 2, 2, 50, 8, 176, "CODE39")

            ''CODE 93
            result = printer.AddBarCode(Define.ROTATE_NONE, Define.BARCODE_93, 2, 2, 50, 8, 252, "CODE93")

            ''BARCODE
            result = printer.AddBarCode(Define.ROTATE_NONE, Define.BARCODE_CODABAR, 2, 2, 50, 8, 328, "A1234567890A")

            'ENA13
            result = printer.AddBarCode(Define.ROTATE_NONE, Define.BARCODE_EAN13, 2, 2, 50, 8, 400, "123456789012")

            'ENA8
            result = printer.AddBarCode(Define.ROTATE_NONE, Define.BARCODE_EAN8, 2, 2, 50, 8, 472, "1234567")

            'QRCODE 2
            result = printer.AddQRCode(Define.ROTATE_NONE, 8, 560, 2, 5, Define.ECC_LEVEL_H, "QRCODE654321")
            'QRCODE 1
            result = printer.AddQRCode(Define.ROTATE_NONE, 200, 560, 1, 5, Define.ECC_LEVEL_H, "QRCODE123456")

            'Image
            result = printer.AddImage(Define.ROTATE_NONE, 200, 700, "0.jpg")

            'LINE
            result = printer.AddLine(8, 700, 8, 900, 2)

            'BOX
            result = printer.AddBox(24, 700, 100, 900, 2)

            result = printer.Print()
            result = printer.DemPortClose()

            'DemDirectIO 示例  必须给定纸张大小以及开启打印功能
            'Dim num1() As Byte = {   &H21, &H20, &H30, &H20, &H32, &H30, &H30, &H20, &H32, &H30, &H30, &H20, &H32, &H30, &H30, &H20, &H31, &HD, &HA, 
            '                         &H50, &H52, &H45, &H46, &H45, &H45, &H44, &H20, &H32, &H30, &HD, &HA,
            '                         &H50, &H52, &H49, &H4E, &H54, &HD, &HA}
            'Dim readnum As Integer
            'printer.DemDirectIO(num1, num1.Length, num1, 0, readnum)
        Else
            MessageBox.Show("Port Open Failed")
        End If
    End Sub
End Class
