コード例 #1
0
ファイル: Form1.cs プロジェクト: joeostrander/ZPL
        private async void ButtonSendZpl_Click(object sender, EventArgs e)
        {
            string strHostname = txtHostname.Text;
            string strPort     = ComboBoxPort.Text;
            string strSendText = TextBox1.Text;

            if (string.IsNullOrEmpty(strHostname))
            {
                MessageBox.Show("Enter a hostname.", "Send ZPL to printer", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtHostname.Focus();
                return;
            }

            if (string.IsNullOrEmpty(strPort))
            {
                MessageBox.Show("Select a port number.", "Send ZPL to printer", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                ComboBoxPort.Focus();
                return;
            }


            if (string.IsNullOrEmpty(strSendText))
            {
                MessageBox.Show("Enter some ZPL to send.", "Send ZPL to printer", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                TextBox1.Focus();
                return;
            }

            int intPort = 9100;

            int.TryParse(ComboBoxPort.Text, out intPort);

            EnableControls(false);
            bool boolStatus = await SendData(strHostname, intPort, strSendText);

            EnableControls(true);
            if (boolStatus)
            {
                MessageBox.Show("ZPL sent", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Failed to send ZPL", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
コード例 #2
0
 private void ComboBoxPort_OnDropDownOpened(object sender, EventArgs e)
 {
     ComboBoxPort.SetBinding(ItemsControl.ItemsSourceProperty, new Binding {
         Source = SerialPort.GetPortNames()
     });
 }