コード例 #1
0
 private void btnSendMail_Click(object sender, EventArgs e)
 {
     btnSendMail.Enabled   = false;
     LogManager.MailServer = txtSMTP.Text;
     LogManager.FromUser   = txtUserID.Text;
     LogManager.FromPWD    = txtPWD.Text;
     LogManager.MailFrom   = txtMailFrom.Text;
     LogManager.MailTo     = txtMailTo.Text;
     LogManager.UseHTML    = chkUseHtml.Checked;
     if (!string.IsNullOrEmpty(cbEncoding.Text))
     {
         LogManager.MailEncoding = Encoding.GetEncoding(cbEncoding.Text);
     }
     try
     {
         string[] attachments = null;
         if (!string.IsNullOrEmpty(txtAttachments.Text))
         {
             attachments = txtAttachments.Text.Split(';');
         }
         LogManager.SendMail(txtSubject.Text, txtContext.Text, true, attachments);
         MessageBox.Show("信件已送出...", "Send Mail", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (Exception ex)
     {
         MessageBox.Show($"發生錯誤!{Environment.NewLine}{ex.Message}", "Send Mail", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     btnSendMail.Enabled = true;
 }
コード例 #2
0
        private void btnShowMsgBox_Click(object sender, EventArgs e)
        {
            labDialogResult.Text = string.Empty;
            MessageBoxButtons       btn    = (MessageBoxButtons)Enum.Parse(typeof(MessageBoxButtons), cbMsgBoxBtn.Text);
            MessageBoxIcon          icon   = (MessageBoxIcon)Enum.Parse(typeof(MessageBoxIcon), cbMsgBoxIcon.Text);
            MessageBoxDefaultButton defBtn = (MessageBoxDefaultButton)Enum.Parse(typeof(MessageBoxDefaultButton), cbMsgBoxDefBtn.Text);

            if (chkFont.Checked)
            {
                MessageBox.Font = new Font((FontFamily)cbMsgBoxFont.SelectedItem, (float)cbMsgBoxFontSize.SelectedItem);
            }
            else if (MessageBox.Font != null)
            {
                MessageBox.Font = null;
            }
            string msg = txtMsgBoxText.Text.Replace("\\x1b", "\\x1B").Replace("\\x1B", "\x1B");

            System.Windows.Forms.MessageBox.Show(msg, "Original MessageBox", btn, icon, defBtn);
            MessageBox.Show(this, msg, "Owner MessageBox", btn, icon, defBtn);
            labDialogResult.Text = MessageBox.Show(CsiBuilder.GetPureText(msg), txtMsgBoxCaption.Text, btn, icon, defBtn).ToString();
            labDialogResult.Text = MessageBox.Show(msg, txtMsgBoxCaption.Text, btn, icon, defBtn).ToString();
        }
コード例 #3
0
        private void btnFile_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;

            if (btn.Tag == null)
            {
                MessageBox.Show("本按鈕未設定對應之文字框!");
                return;
            }
            Control[] cs = btn.Parent.Controls.Find(btn.Tag.ToString(), true);
            if (cs == null || cs.Length == 0)
            {
                return;
            }
            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Filter             = "所有檔案(*.*)|*.*";
                ofd.RestoreDirectory   = true;
                ofd.AutoUpgradeEnabled = true;
                ofd.CheckFileExists    = true;
                ofd.CheckPathExists    = true;
                ofd.Multiselect        = false;
                ofd.Title = "請選擇檔案";
                if (string.IsNullOrEmpty(txtFile.Text))
                {
                    ofd.FileName = string.Empty;
                }
                else
                {
                    ofd.FileName = Path.GetFileName(txtFile.Text);
                }
                DialogResult dr = ofd.ShowDialog(this);
                if (dr != DialogResult.OK)
                {
                    return;
                }
                cs[0].Text = ofd.FileName;
            }
        }
コード例 #4
0
        private void btnGetBytes_Click(object sender, EventArgs e)
        {
            switch (cbDataType.SelectedItem.ToString())
            {
            case "Short":
                txtGetBytesResult.Text = short.Parse(txtGetBytes.Text).GetBytes(chkBigEndian.Checked).ToHexString();
                txtBitConv.Text        = BitConverter.ToInt16(txtGetBytesResult.Text.ToByteArray(), 0).ToString();
                break;

            case "Int":
                txtGetBytesResult.Text = int.Parse(txtGetBytes.Text).GetBytes(chkBigEndian.Checked).ToHexString();
                txtBitConv.Text        = BitConverter.ToInt32(txtGetBytesResult.Text.ToByteArray(), 0).ToString();
                break;

            case "Long":
                txtGetBytesResult.Text = long.Parse(txtGetBytes.Text).GetBytes(chkBigEndian.Checked).ToHexString();
                txtBitConv.Text        = BitConverter.ToInt64(txtGetBytesResult.Text.ToByteArray(), 0).ToString();
                break;

            case "UShort":
                txtGetBytesResult.Text = ushort.Parse(txtGetBytes.Text).GetBytes(chkBigEndian.Checked).ToHexString();
                txtBitConv.Text        = BitConverter.ToUInt16(txtGetBytesResult.Text.ToByteArray(), 0).ToString();
                break;

            case "UInt":
                txtGetBytesResult.Text = uint.Parse(txtGetBytes.Text).GetBytes(chkBigEndian.Checked).ToHexString();
                txtBitConv.Text        = BitConverter.ToUInt32(txtGetBytesResult.Text.ToByteArray(), 0).ToString();
                break;

            case "ULong":
                txtGetBytesResult.Text = ulong.Parse(txtGetBytes.Text).GetBytes(chkBigEndian.Checked).ToHexString();
                txtBitConv.Text        = BitConverter.ToUInt64(txtGetBytesResult.Text.ToByteArray(), 0).ToString();
                break;

            default:
                MessageBox.Show("No Support");
                break;
            }
        }
コード例 #5
0
        private void btnSearchHex_Click(object sender, EventArgs e)
        {
            if (!File.Exists(txtFile.Text))
            {
                MessageBox.Show("檔案不存在!!");
                return;
            }
            if (string.IsNullOrEmpty(txtHexStr.Text))
            {
                MessageBox.Show("請輸入欲搜尋的 16 進位陣列字串!!");
                return;
            }
            this.UseWaitCursor = true;
            Application.DoEvents();
            string msg = string.Empty;

            byte[] sch = txtHexStr.Text.ToByteArray();
            int    idx = 0, start = 0;

            if (btnSearchHex.Tag != null)
            {
                start = Convert.ToInt32(btnSearchHex.Tag) + 1;
            }
            Stopwatch w = new Stopwatch();

            w.Start();
            if (!rbFindIndexes.Checked)
            {
                if (rbIndexOfBytes.Checked)
                {
                    byte[] buf = File.ReadAllBytes(txtFile.Text);
                    idx = buf.IndexOfBytes(sch, start);
                }
                else if (rbFindIndex.Checked)
                {
                    idx = ConvUtils.IndexOfBytesInFile(txtFile.Text, sch, start);
                }
                w.Stop();
                if (idx == -1)
                {
                    msg = string.Format("找不到欲搜尋的 16 進位陣列字串!!\n耗時:{0}ms / {1}ticks\n\n", w.ElapsedMilliseconds, w.ElapsedTicks);
                    btnSearchHex.Tag = null;
                }
                else
                {
                    msg = string.Format("欲搜尋的 16 進位陣列字串的索引值為 {0:X8}\n耗時:{1}ms / {2}ticks\n\n", idx, w.ElapsedMilliseconds, w.ElapsedTicks);
                    btnSearchHex.Tag = idx;
                }
            }
            else
            {
                int[] idxs = ConvUtils.IndexesOfBytesInFile(txtFile.Text, sch);
                w.Stop();
                if (idxs.Length == 0)
                {
                    msg = string.Format("找不到欲搜尋的 16 進位陣列字串!!\n耗時:{0}ms / {1}ticks\n\n", w.ElapsedMilliseconds, w.ElapsedTicks);
                    btnSearchHex.Tag = null;
                }
                else
                {
                    msg = string.Format("搜尋 16 進位陣列字串耗時:{0}ms / {1}ticks, 索引值為:\n", w.ElapsedMilliseconds, w.ElapsedTicks);
                    foreach (int ii in idxs)
                    {
                        msg += string.Format("{0:X8}\n", ii);
                    }
                    btnSearchHex.Tag = null;
                }
            }
            this.UseWaitCursor = false;
            Application.DoEvents();
            MessageBox.Show(msg);
        }