C# 在事件处理程序函数内调用方法

C# 在事件处理程序函数内调用方法,c#,zxing,C#,Zxing,我正在尝试用C#实现一个应用程序,它会为我生成一个二维码。我已经设法做到了这一点,但我不知道如何在genButton_Click(objectsender,EventArgs e)中调用CreateQRImage(stringinputdata) 我在windows窗体中有一个文本框和一个按钮,我认为必须使用文本框的名称调用函数CreateQRImage 代码如下: private void genButton_Click(object sender, EventArgs e) { } pu

我正在尝试用C#实现一个应用程序,它会为我生成一个二维码。我已经设法做到了这一点,但我不知道如何在genButton_Click(objectsender,EventArgs e)中调用CreateQRImage(stringinputdata)

我在windows窗体中有一个文本框和一个按钮,我认为必须使用文本框的名称调用函数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);
}

这应该可以做到:

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);
}

此.CreateQRImage(“”);传递正确的inputData参数值它要求我为此函数生成方法存根您还知道如何在PNG文件中插入生成二维码的文本吗?