更改事件内的文本框值

本文关键字:文本 事件 | 更新日期: 2023-09-27 18:08:28

我有扫描器事件,当这个事件发生时,我有代码来保存我读到它的扫描器到文本框。

当我跟踪这个时,它工作得很好,但是屏幕上没有显示用户

这个代码里面的按钮点击:

  protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            //Instantiate CoreScanner Class
            cCoreScannerClass = new CCoreScannerClass();
            //Call Open API
            short[] scannerTypes = new short[1];//Scanner Types you are interested in
            scannerTypes[0] = 1; // 1 for all scanner types
            short numberOfScannerTypes = 1; // Size of the scannerTypes array
            int status; // Extended API return code
            cCoreScannerClass.Open(0, scannerTypes, numberOfScannerTypes, out status);
            // Subscribe for barcode events in cCoreScannerClass
            cCoreScannerClass.BarcodeEvent += new
            _ICoreScannerEvents_BarcodeEventEventHandler(OnBarcodeEvent);
            // Let's subscribe for events
            int opcode = 1001; // Method for Subscribe events
            string outXML; // XML Output
            string inXML = "<inArgs>" +
            "<cmdArgs>" +
            "<arg-int>1</arg-int>" + // Number of events you want to subscribe
            "<arg-int>1</arg-int>" + // Comma separated event IDs
            "</cmdArgs>" +
            "</inArgs>";
            cCoreScannerClass.ExecCommand(opcode, ref inXML, out outXML, out status);
            Console.WriteLine(outXML);
        }
        catch (Exception exp)
        {
            Console.WriteLine("Something wrong please check... " + exp.Message);
        }
    }

事件发生后的代码:

void OnBarcodeEvent(short eventType, ref string pscanData)
{
    first = pscanData;
      printfunction();
        }

下面的代码在printfunction函数之后写入到文本框:

private void printfunction()
    {
        int l = first.IndexOf("<datalabel>");
        second = first.Substring(l + 11);
        int j = second.IndexOf("</datalabel>");
        second = second.Substring(0,j-1);
        string newValue = second.Replace("0x", ""); ;
        newValue = newValue.Replace(" ", string.Empty);
        txt = GetStringFromAsciiHex(newValue);
       TextBox1.Text = txt;
     }

请帮帮我。谢谢你。

更改事件内的文本框值

您的局部变量txt是否包含正确的值?如果是,则在设置文本后尝试TextBox1.Refresh()