伊莉討論區

標題: winform的Keypress的問題 [打印本頁]

作者: tw00167789    時間: 2017-7-13 03:19 AM     標題: winform的Keypress的問題

各位大大好:
我有一個winform  出貨單, 其中有個TextBox是廠商代號, 我想要在這個欄位中如輸入"?"問號(使用KeyPress), 則會跳出搜尋廠商的對話框, 找到資料後, 關閉對話框, 把找到的廠商代號填入原表單的TextBox中, 但不知為何, TextBox都會出現一個"?"號, 我有試過用其他字元, 也都會有這種狀況, 請問有那位大大知道如何解決嗎?
  1. private void txtSupplierNumber_KeyPress(object sender, KeyPressEventArgs e)
  2.         {
  3.             //捕捉?號
  4.             if (e.KeyChar == '?')
  5.             {
  6.                 GetSupplierData();
  7.             }
  8.         }
複製代碼
  1. private void GetSupplierData()
  2.         {
  3.             frmQrySupplier frm = new UI.frmQrySupplier();
  4.             //問啟搜尋廠商資料對話框
  5.             if (frm.ShowDialog() == DialogResult.OK)
  6.             {
  7.                 Supplier supplier = SupplierBLL.GetById(frm.SearchId);
  8.                 if (supplier != null)
  9.                 {
  10.                     //如果找到資料, 則將廠商代碼,名稱,地址輸入到各欄位
  11.                     lblSupplierName.Text = supplier.Name;
  12.                     txtShipAddress.Text = supplier.Address;
  13.                     txtSupplierNumber.Text = supplier.Number;
  14.                 }
  15.             }
  16.         }
複製代碼

找到資料後, 結果txtSupplierNumber這個TextBox就是會多一個問號
[attach]119483254[/attach]


作者: tw00167789    時間: 2017-7-13 07:54 AM

已解決了
  1. private void txtSupplierNumber_KeyPress(object sender, KeyPressEventArgs e)
  2.         {
  3.             //捕捉?號
  4.             if (e.KeyChar == '?')
  5.             {
  6.                 //禁止輸入
  7.                 e.Handled = true;
  8.                 GetSupplierData();
  9.             }
  10.         }
複製代碼





歡迎光臨 伊莉討論區 (http://s03.p02.eyny.com/) Powered by Discuz!