C# winform 新手實(shí)例:點(diǎn)擊生成二維碼
效果圖如下:

打開(kāi)exe默認(rèn)界面
部分代碼:
//button點(diǎn)擊事件private void button1_Click(object sender, EventArgs e){  if (string.IsNullOrEmpty(textBox1.Text))  {   MessageBox.Show("請(qǐng)輸入要生成的二維碼!");   return;  }  GenByZXingNet(textBox1.Text);}//生成二維碼圖片的函數(shù)private Bitmap GenByZXingNet(string msg) {  BarcodeWriter writer = new BarcodeWriter();  writer.Format = BarcodeFormat.QR_CODE;  writer.Options.Hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8");//編碼問(wèn)題  writer.Options.Hints.Add(EncodeHintType.ERROR_CORRECTION, ZXing.QrCode.Internal.ErrorCorrectionLevel.H);  const int codeSizeInPixels = 240; //設(shè)置圖片長(zhǎng)寬  writer.Options.Height = writer.Options.Width = codeSizeInPixels;  writer.Options.Margin = 1;//設(shè)置邊框  ZXing.Common.BitMatrix bm = writer.Encode(msg);  Bitmap img = writer.Write(bm);  pictureBox1.Image = img;  return img; }//若需要打開(kāi)exe默認(rèn)出現(xiàn)一張二維碼,先給textbox初始值,然后添加函數(shù)private void Form1_Load(object sender, EventArgs e) {  button1_Click(null,null); }以上所述是小編給大家介紹的 C# winform點(diǎn)擊生成二維碼實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)武林網(wǎng)網(wǎng)站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選