/// <summary> /// 生成二维码 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnMakeQr_Click(object sender, EventArgs e) { //如果选择开启图标 if (radioButton2.Checked) { if (!triggerIcon) { MessageBox.Show("未选择图标。", "出错了!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } qrBitmap = QRCoderHelper.QrMaker(richTextBox1.Text, trackBar1.Value, trackBar2.Value, label12.Text, trackBar3.Value, trackBar4.Value, radioButton4.Checked); } else//反之 { if (string.IsNullOrEmpty(richTextBox1.Text)) { MessageBox.Show("未输入二维码内容。", "出错了!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } qrBitmap = QRCoderHelper.QrMaker(richTextBox1.Text, trackBar1.Value, trackBar2.Value, radioButton4.Checked); } pictureBox1.Image = qrBitmap; panel1.Visible = false; pictureBox1.Visible = true; triggerDrag = true; CheckQrCodeWorks(); }
/// <summary> /// 拖入二维码的时候。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MainForm_DragEnter(object sender, DragEventArgs e) { var paths = e.Data.GetData(typeof(string[])) as string[]; richTextBox1.Text = QRCoderHelper.QrDecoder(paths[0]); pictureBox1.Image = new Bitmap(paths[0]); qrBitmap = new Bitmap(paths[0]); panel1.Visible = false; pictureBox1.Visible = true; BtnMakeQr.Text = "重新生成"; triggerDrag = true; }
/// <summary> /// 检测二维码是否可用 /// </summary> private void CheckQrCodeWorks() { if (qrBitmap == null) { MessageBox.Show("未生成二维码", "出错了!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (QRCoderHelper.QrDecoder(qrBitmap) != "error") { MessageBox.Show("检测结果:该二维码可用~", "检测完成", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); triggerChecked = true; return; } else { MessageBox.Show("检测结果:该二维码不可用,可能是二维码内容超出限制。" + "\n" + " 建议提高\'容量级别\'~", "检测完成", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); triggerChecked = false; return; } }