0

バーコードをスキャンしてログインする登録システムがあります。バーコードには、「*」に続く一意の番号が含まれています。彼らがコードをスキャンすると、リストボックスに入り、テキストボックスから残りをクリアしますが、「 * 」はクリアされません。

何か案は ?ここにコードのチャックがあります:

private void textBox1_KeyUp(object sender, KeyPressEventArgs e)
        {
        Object returnValue;

        string txtend = textBox1.Text;
        returnValue = textBox1.Text.Replace(@"*", "");

        if (e.KeyChar != '*') return;
        {
          if (listBox1.Items.Contains(returnValue))
           {
             for (int n = listBox1.Items.Count - 1; n >= 0; --n)
              {
               string removelistitem = returnValue.ToString();
               if (listBox1.Items[n].ToString().Contains(removelistitem))
               {
                //listBox1.Items.RemoveAt(n);
               }
             }
           }
          else
          listBox1.Items.Add(returnValue);
          textBox1.Clear();
          System.IO.StreamWriter sw = new System.IO.StreamWriter(fullFileName);
          foreach (object item in listBox1.Items)
          sw.WriteLine(item.ToString());
          sw.Flush();
          sw.Close();
          if (listBox1.Items.Count != 0) { DisableCloseButton(); }
          else
          {
            EnableCloseButton();
          }
          label6.Text = "Currently " + listBox1.Items.Count.ToString() + " in attendance.";
        }
    }
4

2 に答える 2

2

この行

if (e.KeyChar != '*') return;

押されたキーが「*」でない場合、イベント処理を早期に終了します。次の { } ブロックでは、古い/テスト中の遺物のように見えます。

elseまた、最初のif-Blockの後に問題がある可能性があります。ブロックに 1 行しかない場合でも、常に { } を使用することをお勧めします。

于 2013-09-24T15:36:10.100 に答える