using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CSharpSample
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            BtnFeed.Enabled = false;
            BtnBitmap.Enabled = false;
            Btn1DBar.Enabled = false;
            BtnSample.Enabled = false;
            BtnStatus.Enabled = false;
            BtnProperty.Enabled = false;
            BtnDirect.Enabled = false;
            BtnMSRStart.Enabled = false;
            BtnMSRCancel.Enabled = false;
            BtnLabel.Enabled = false;
            BtnReceipt.Enabled = false;
            BtnText.Enabled = false;
            Btn2DBar.Enabled = false;
            BtnPageMode.Enabled = false;
            BtnPageSample.Enabled = false;
            BtnAutoCalibration.Enabled = false;

            LblTrack1.Text = "Click to MSRStart Button";
            LblTrack2.Text = "";
            LblTrack3.Text = "";
        }

        private void BtnOpen_Click(object sender, EventArgs e)
        {
         
            string strPort = textBox1.Text;
            int ret = 0;

            if ((ret = BxlPrint.PrinterOpen(strPort, 1000)) != BxlPrint.BXL_SUCCESS)
            {
                MessageBox.Show("Open Failed!");
                return;
            }

            BtnFeed.Enabled = true;
            BtnBitmap.Enabled = true;
            Btn1DBar.Enabled = true;
            BtnSample.Enabled = true;
            BtnStatus.Enabled = true;
            BtnProperty.Enabled = true;
            BtnDirect.Enabled = true;
            BtnMSRStart.Enabled =true;
            BtnMSRCancel.Enabled = true;
            BtnLabel.Enabled = true;
            BtnReceipt.Enabled = true;
            BtnText.Enabled = true;
            Btn2DBar.Enabled = true;
            BtnPageMode.Enabled = true;
            BtnPageSample.Enabled = true;
            BtnAutoCalibration.Enabled = true;
        }

        private void BtnClose_Click(object sender, EventArgs e)
        {
            BxlPrint.PrinterClose();
            BtnFeed.Enabled = false;
            BtnBitmap.Enabled = false;
            Btn1DBar.Enabled = false;
            BtnSample.Enabled = false;
            BtnStatus.Enabled = false;
            BtnProperty.Enabled = false;
            BtnDirect.Enabled = false;
            BtnMSRStart.Enabled = false;
            BtnMSRCancel.Enabled = false;
            BtnLabel.Enabled = false;
            BtnReceipt.Enabled = false;
            BtnText.Enabled = false;
            Btn2DBar.Enabled = false;
            BtnPageMode.Enabled = false;
            BtnPageSample.Enabled = false;
            BtnAutoCalibration.Enabled = false;
        }

        private void BtnFeed_Click(object sender, EventArgs e)
        {
            BxlPrint.LineFeed(10);    
        }

        private void BtnBitmap_Click(object sender, EventArgs e)
        {
             string strDirBmp = string.Empty;

             OpenFileDialog dlg = new OpenFileDialog();
             dlg.InitialDirectory = "\\";
             dlg.Filter = "bmp file (*.bmp)|*.bmp; |jpg file (*.jpg)|*.jpg; |gif file (*.gif)|*.gif; |all file(*.*)|*.*;";
             //dlg.Filter = "bmp file (*.bmp)|*.bmp;";

             if (dlg.ShowDialog() != DialogResult.OK)
             {
                 MessageBox.Show("Error File Open");
                 return;
             }

             strDirBmp = dlg.FileName;


             if (BxlPrint.PrintBitmap(strDirBmp, 300, BxlPrint.BXL_ALIGNMENT_CENTER, 10050) != BxlPrint.BXL_SUCCESS)
                MessageBox.Show("Error PrintBitmap");            
        }

        private void Btn1DBar_Click(object sender, EventArgs e)
        {
            //Sample UPCA Barcode print

            byte[] bytes = new byte[12] {0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32};

            BxlPrint.PrintText("UPCA\n", BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintBarcode(bytes, BxlPrint.BXL_BCS_UPCA, 50, 2, BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_BC_TEXT_BELOW);

            BxlPrint.PrintText("UPCE\n", BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintBarcode(bytes, BxlPrint.BXL_BCS_UPCE, 50, 2, BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_BC_TEXT_BELOW);

            BxlPrint.PrintText("EAN13\n", BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintBarcode(bytes, BxlPrint.BXL_BCS_EAN13, 50, 2, BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_BC_TEXT_BELOW);

            BxlPrint.PrintText("JAN13\n", BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintBarcode(bytes, BxlPrint.BXL_BCS_JAN13, 50, 2, BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_BC_TEXT_BELOW);

            byte[] bytes1 = new byte[8] { 0x31, 0x32, 0x33, 0x34, 0x34, 0x35, 0x36, 0x38 };
            BxlPrint.PrintText("EAN8\n", BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintBarcode(bytes1, BxlPrint.BXL_BCS_EAN8, 50, 2, BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_BC_TEXT_BELOW);

            BxlPrint.PrintText("JAN8\n", BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintBarcode(bytes1, BxlPrint.BXL_BCS_JAN8, 50, 2, BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_BC_TEXT_BELOW);

            byte[] bytes2 = new byte[12] { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32 };

            BxlPrint.PrintText("Code 39\n", BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintBarcode(bytes2, BxlPrint.BXL_BCS_Code39, 50, 2, BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_BC_TEXT_BELOW);

            BxlPrint.PrintText("ITF\n", BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintBarcode(bytes2, BxlPrint.BXL_BCS_ITF, 50, 2, BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_BC_TEXT_BELOW);

            BxlPrint.PrintText("Codebar\n", BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintBarcode(bytes2, BxlPrint.BXL_BCS_Codabar, 50, 2, BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_BC_TEXT_BELOW);

            BxlPrint.PrintText("Code 93\n", BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintBarcode(bytes2, BxlPrint.BXL_BCS_Code93, 50, 2, BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_BC_TEXT_BELOW);

            BxlPrint.PrintText("Code 128\n", BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintBarcode(bytes2, BxlPrint.BXL_BCS_Code128, 50, 2, BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_BC_TEXT_BELOW);

            BxlPrint.LineFeed(5);
        }

        private void Btn2DBar_Click(object sender, EventArgs e)
        {
            //Sample UPCA Barcode print

            byte[] bytes = new byte[12] { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32 };

            BxlPrint.PrintText("PDF417\n", BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintBarcode(bytes, BxlPrint.BXL_BCS_PDF417, 0, 2, BxlPrint.BXL_ALIGNMENT_LEFT, 0);

            BxlPrint.PrintText("QRCODE\n", BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintBarcode(bytes, BxlPrint.BXL_BCS_QRCODE_MODEL1, 0, 2, BxlPrint.BXL_ALIGNMENT_LEFT, 0);

            BxlPrint.PrintText("QRCODE\n", BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintBarcode(bytes, BxlPrint.BXL_BCS_QRCODE_MODEL2, 0, 2, BxlPrint.BXL_ALIGNMENT_LEFT, 0);

            BxlPrint.PrintText("DATAMATRIX\n", BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintBarcode(bytes, BxlPrint.BXL_BCS_DATAMATRIX, 0, 2, BxlPrint.BXL_ALIGNMENT_LEFT, 0);

            BxlPrint.PrintText("MAXICODE\n", BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintBarcode(bytes, BxlPrint.BXL_BCS_MAXICODE_MODE4, 0, 2, BxlPrint.BXL_ALIGNMENT_LEFT, 0);
            

            BxlPrint.LineFeed(5);

        }


        private void BtnSample_Click(object sender, EventArgs e)
        {
            BxlPrint.SetCharacterSet(BxlPrint.BXL_CS_WPC1251);
            BxlPrint.SetInterChrSet(BxlPrint.BXL_ICS_USA);

            BxlPrint.PrintText("Receipt\n", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_BOLD | BxlPrint.BXL_FT_UNDERLINE, BxlPrint.BXL_TS_1WIDTH | BxlPrint.BXL_TS_1HEIGHT);	
            BxlPrint.PrintText("\n\n", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_BOLD | BxlPrint.BXL_FT_UNDERLINE, BxlPrint.BXL_TS_1WIDTH | BxlPrint.BXL_TS_1HEIGHT);

            BxlPrint.PrintText("------------------------------\n", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintText(" Apple      3             $3.0\n", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintText(" Cola       1             $1.2\n", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintText(" Milk       2             $1.8\n", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintText(" Juice      1             $2.0\n", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintText("------------------------------\n", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintText(" Total                    $8.0\n", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_BOLD, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintText(" Cash                     $8.0\n", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_BOLD, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintText("                          $0.0\n", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_BOLD, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);

            //////////////////////////////////////////////////////////////////////////
            //Set multi attribute in one line.
            BxlPrint.PrintText("Test", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_BOLD, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintText("BBB", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_FONTB | BxlPrint.BXL_FT_BOLD, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintText("CCC", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_FONTB | BxlPrint.BXL_FT_REVERSE, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintText("DDD", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_BOLD | BxlPrint.BXL_FT_UNDERLINE, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintText("\n", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_BOLD | BxlPrint.BXL_FT_UNDERLINE, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);

            BxlPrint.PrintText("ABCDEFabcdef\n", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintText("ABCDEFabcdef\n", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_FONTB, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintText("ABCDEFabcdef\n", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_FONTC, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
           

            Int32 lResult = BxlPrint.LineFeed(5);

            if(lResult != BxlPrint.BXL_SUCCESS)
            {
	            MessageBox.Show("Error LineFeeding");
            }
        }

        private void BtnStatus_Click(object sender, EventArgs e)
        {
            //bool bNormal = true;
            
            if( BxlPrint.CheckPrinter() != BxlPrint.BXL_SUCCESS)
            {
                MessageBox.Show("Printer is Error");
           //     bNormal = false;
            }
            else
            {
                Int32 lResult;
                lResult = BxlPrint.GetStat();// 'lResult Value is BXL_STS.... 

                string strStatus;

                if ((lResult & BxlPrint.BXL_STS_COVEROPEN) != 0)
                {
                    strStatus = "Cover : Open";
                }
                else
                {
                    strStatus = "Cover : Close";
                }

                if ((lResult & BxlPrint.BXL_STS_PAPEREMPTY) != 0)
                {
                    strStatus += "  Paper : Empty";
                }
                else
                {
                    strStatus += "  Paper : OK";
                }

                MessageBox.Show(strStatus);

                lResult = BxlPrint.GetPowerValue();

                string strPower;

                if (lResult == BxlPrint.BXL_PWR_FULL)
                    strPower = "Battery : Full. 75~100%";
                else if (lResult == BxlPrint.BXL_PWR_HIGH)
                    strPower = "Battery : High. 50~75%";
                else if (lResult == BxlPrint.BXL_PWR_MIDDLE)
                    strPower = "Battery : Middle. 10~50%";
                else if (lResult == BxlPrint.BXL_PWR_LOW)
                    strPower = "Battery : Low. under 10%";
                else
                    strPower = "Failed to check battery.";

                MessageBox.Show(strPower);
            }           
            
        }

        private void BtnProperty_Click(object sender, EventArgs e)
        {
            Int32 nCharSet;
            BxlPrint.SetCharacterSet(BxlPrint.BXL_CS_PC850);

            nCharSet = BxlPrint.GetCharacterSet();
            if(nCharSet != BxlPrint.BXL_CS_PC850 )
                MessageBox.Show("Failed to set SetCharacterSet");
            else
                MessageBox.Show("Success to set SetCharacterSet");
        
            BxlPrint.SetInterChrSet(BxlPrint.BXL_ICS_FRANCE);

            nCharSet = BxlPrint.GetInterChrSet();
            if(nCharSet != BxlPrint.BXL_ICS_FRANCE)
                MessageBox.Show("Failed to set International CharacterSet");
            else
                MessageBox.Show("Success to set International CharacterSet");
        
        }

        private void BtnDirect_Click(object sender, EventArgs e)
        {
            // DirectIO Test
            byte[] bytes = new byte[3] {0x20, 0x04,1};  // DLE EOT 
            byte[] ReadBuf = new byte[2] {0,0};
            UInt32 nbyte;
            UInt32 nRead;
            Int32 lResult ;

            nRead = 1;
            nbyte = 3;
            
            lResult = BxlPrint.DirectIO(bytes, nbyte, ReadBuf,ref nRead);

            if(lResult == BxlPrint.BXL_SUCCESS)
            {
                if(ReadBuf[0] == 18)
                    MessageBox.Show("Success");
            }                
        }

        private void BtnMSRStart_Click(object sender, EventArgs e)
        {
            BxlPrint.MsrReadReady();

            if(BxlPrint.GetStat() != BxlPrint.BXL_STS_MSR_READY)
              return;
            
            LblTrack1.Text = "Ready MSR Mode...";
            LblTrack2.Text = "";
            LblTrack3.Text = "";
            
            timer1.Enabled = true;
        }

        private void BtnMSRCancel_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            BxlPrint.MsrReadCancel();

            LblTrack1.Text = "Please 'MSRStart' Button";
            LblTrack2.Text = "";
            LblTrack3.Text = "";

        }

        public const Int32 BXL_TRACK = 200;
        private void timer1_Tick(object sender, EventArgs e)
        {
            if(radioButton1.Checked)
                read_track_function();
            else        
                read_track_function2();                
        }
        //use MsrReadTrack Funtion

        private void read_track_function()
        {
            byte[] cTrack1 = new byte[BXL_TRACK];
            byte[] cTrack2 = new byte[BXL_TRACK];
            byte[] cTrack3 = new byte[BXL_TRACK];

            Int32 lResult;
            ASCIIEncoding ascii = new ASCIIEncoding();


            lResult = BxlPrint.MsrReadTrack(cTrack1, cTrack2, cTrack3);

            if (lResult == BxlPrint.BXLMSR_DATAEMPTY)
                return;                       
            
            LblTrack1.Text = ascii.GetString(cTrack1, 0, BXL_TRACK);
            LblTrack2.Text = ascii.GetString(cTrack2, 0, BXL_TRACK);
            LblTrack3.Text = ascii.GetString(cTrack3, 0, BXL_TRACK);

            timer1.Enabled = false;
        }
        
        //use MsrReadFullTrack Funtion
        private void read_track_function2()
        {
            byte[] cTrack = new byte[600];
            Int32 lResult;  


            lResult = BxlPrint.MsrReadFullTrack(cTrack, 600);
            if (lResult != BxlPrint.BXL_SUCCESS)
                return;

            ASCIIEncoding ascii = new ASCIIEncoding();
            LblTrack1.Text = "Use MSRReadFullTrack Functions";
            LblTrack2.Text = ascii.GetString(cTrack, 0, 600);           
            LblTrack3.Text = "";

            timer1.Enabled = false;
        }


        private void BtnAutoCalibration_Click(object sender, EventArgs e)
        {
            BxlPrint.AutoCalibration();
        }

        private void BtnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if ((e.KeyCode == System.Windows.Forms.Keys.Up))
            {
                // 로커 위로
                // 위로
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Down))
            {
                // 로커 아래로
                // 아래로
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Left))
            {
                // 왼쪽
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Right))
            {
                // 오른쪽
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Enter))
            {
                // Enter
            }
        }

        private void BtnLabel_Click(object sender, EventArgs e)
        {
            BxlPrint.SelectMode(true);
        }

        private void BtnReceipt_Click(object sender, EventArgs e)
        {
            BxlPrint.SelectMode(false);
        }

        private void BtnText_Click(object sender, EventArgs e)
        {
            BxlPrint.SetCharacterSet(BxlPrint.BXL_CS_WPC1251);
            BxlPrint.SetInterChrSet(BxlPrint.BXL_ICS_USA);

            BxlPrint.PrintText("Left, Default\n", BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintText("Center, FontB\n", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_FONTB, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintText("Right, FontC\n", BxlPrint.BXL_ALIGNMENT_RIGHT, BxlPrint.BXL_FT_FONTC, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);

            BxlPrint.PrintText("Center, Bold, Default\n", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_BOLD | BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintText("Center, Bold, FontB\n", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_BOLD | BxlPrint.BXL_FT_FONTB, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintText("Center, Bold, FontC\n", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_BOLD | BxlPrint.BXL_FT_FONTC, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);

            BxlPrint.PrintText("Left, Underline\n", BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_FT_UNDERLINE | BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintText("Right, Reverse\n", BxlPrint.BXL_ALIGNMENT_RIGHT, BxlPrint.BXL_FT_REVERSE | BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);

            BxlPrint.PrintText("Left, Default, 0W 0H\n", BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintText("Left, Default, 1W 0H\n", BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_1WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.PrintText("Left, Default, 0W 1H\n", BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_1HEIGHT);
            BxlPrint.PrintText("Left, Default, 1W 1H\n", BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_FT_DEFAULT, BxlPrint.BXL_TS_1WIDTH | BxlPrint.BXL_TS_1HEIGHT);

            BxlPrint.LineFeed(5);
        }

        private void BtnPageMode_Click(object sender, EventArgs e)
        {
            BxlPrint.SelectPageMode(true);
        }

        private void BtnPageSample_Click(object sender, EventArgs e)
        {
            BxlPrint.InitializePrinter();
            BxlPrint.SelectPageMode(true);
            BxlPrint.SetPrintAreaInPM(0, 0, 416, 416);
            BxlPrint.SetPrintDirectionInPM(BxlPrint.BXL_PD_TOP_TO_BOTTOM);

            string barCode = "1234567890123";

            byte[] bytes = System.Text.Encoding.ASCII.GetBytes(barCode);

            BxlPrint.SetVerticalPositionInPM(70);
            BxlPrint.SetHorizontalPositionInPM(5);

            BxlPrint.PrintBarcode(bytes, BxlPrint.BXL_BCS_Code93, 50, 2, BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_BC_TEXT_NONE);

            BxlPrint.SetVerticalPositionInPM(155);
            BxlPrint.SetHorizontalPositionInPM(80);
            BxlPrint.PrintText(barCode, BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_DEFAULT,
                                BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);

            BxlPrint.SetVerticalPositionInPM(200);
            BxlPrint.SetHorizontalPositionInPM(0);
            BxlPrint.PrintText("Name :", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_ExFT_CHINA_FONTB,
                                BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.SetVerticalPositionInPM(200);
            BxlPrint.SetHorizontalPositionInPM(90);

            BxlPrint.PrintText(" Frank  ", BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_ExFT_CHINA_FONTA |
                                BxlPrint.BXL_FT_UNDERTHICK | BxlPrint.BXL_FT_BOLD, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.SetVerticalPositionInPM(200);
            BxlPrint.SetHorizontalPositionInPM(180);
            BxlPrint.PrintText("Sex  :", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_ExFT_CHINA_FONTA |
                                BxlPrint.BXL_TS_0WIDTH, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.SetVerticalPositionInPM(200);
            BxlPrint.SetHorizontalPositionInPM(260);
            BxlPrint.PrintText("  male   ", BxlPrint.BXL_ALIGNMENT_LEFT, BxlPrint.BXL_ExFT_CHINA_FONTA |
                                BxlPrint.BXL_FT_UNDERTHICK | BxlPrint.BXL_FT_BOLD, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);

            BxlPrint.SetVerticalPositionInPM(250);
            BxlPrint.SetHorizontalPositionInPM(0);
            BxlPrint.PrintText("Age  :", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_ExFT_CHINA_FONTA,
                                BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.SetVerticalPositionInPM(250);
            BxlPrint.SetHorizontalPositionInPM(90);
            BxlPrint.PrintText("  30  ", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_ExFT_CHINA_FONTA |
                                BxlPrint.BXL_FT_UNDERTHICK | BxlPrint.BXL_FT_BOLD, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.SetVerticalPositionInPM(250);
            BxlPrint.SetHorizontalPositionInPM(180);
            BxlPrint.PrintText("City :", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_ExFT_CHINA_FONTA |
                                BxlPrint.BXL_TS_0WIDTH, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);
            BxlPrint.SetVerticalPositionInPM(250);
            BxlPrint.SetHorizontalPositionInPM(260);
            BxlPrint.PrintText("  Seoul  ", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_ExFT_CHINA_FONTA |
                                BxlPrint.BXL_FT_UNDERTHICK | BxlPrint.BXL_FT_BOLD, BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);


            BxlPrint.SetVerticalPositionInPM(360);
            BxlPrint.SetHorizontalPositionInPM(60);
            BxlPrint.PrintText("abcdefgHIJK-123", BxlPrint.BXL_ALIGNMENT_CENTER, BxlPrint.BXL_FT_DEFAULT,
                                BxlPrint.BXL_TS_0WIDTH | BxlPrint.BXL_TS_0HEIGHT);

            BxlPrint.PrintDataInPageMode();
            
            BxlPrint.LineFeed(2);

        }

    }
}