2015-04-29 28 views
-1

我試圖在C#中實現一個應用程序,該應用程序生成一個QR碼。我設法做到了這一點,但我不知道如何在genButton_Click(object sender,EventArgs e)中調用CreateQRImage(string inputData)。調用事件處理函數內部的方法

我的窗內形成我有一個文本框和一個按鈕,我認爲功能CreateQRImage必須與文本

這裏的名字被稱爲是代碼:

private void genButton_Click(object sender, EventArgs e) 
{ 

} 

public void CreateQRImage(string inputData) 
{ 
    if (inputData.Trim() == String.Empty) 
    { 
     System.Windows.Forms.MessageBox.Show("Data must not be empty."); 
    } 

    BarcodeWriter qrcoder = new ZXing.BarcodeWriter 
    { 
     Format = BarcodeFormat.QR_CODE, 
     Options = new ZXing.QrCode.QrCodeEncodingOptions 
     { 
      ErrorCorrection = ZXing.QrCode.Internal.ErrorCorrectionLevel.H, 
      Height = 250, 
      Width = 250 
     } 
    }; 

    string tempFileName = System.IO.Path.GetTempPath() + inputData + ".png"; 

    Image image; 
    String data = inputData; 
    var result = qrcoder.Write(inputData); 
    image = new Bitmap(result); 
    image.Save(tempFileName); 

    System.Diagnostics.Process.Start(tempFileName); 
} 
+0

this.CreateQRImage(「」);通過正確的inputData參數值 –

+0

它問我爲這個函數生成一個方法存根 – Valip

回答

1

這應該這樣做:

private void genButton_Click(object sender, EventArgs e) 
{ 
    // Assuming your text box name. Also assuming UI disables button until text is entered. 
    this.CreateQRImage(myTextBox.Text); 
} 
+0

你也知道如何插入在PNG文件中生成QR碼的文本? – Valip

相關問題