[英]How to make TextBox handle text like a hyperterminal in c#?
當用戶輸入焦點對准TextBox的字符時,我根本不希望字符出現在TextBox上,並且我也不想使用Clear()方法,因為我可能不會在TextBox中看到其他文本不想刪除。 到目前為止,我已經嘗試過:
private void WriteBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)13) // enter key pressed
{
WriteBox1.Text = "";
}
// Code to write Serial....
String writeValues = WriteBox1.Text;
String withoutLast = writeValues.Substring(0, 1);
WriteBox1.Text = withoutLast;
}
這將保留在writeBox1中輸入的最后一個字母。 我需要它來刪除所有輸入的字符。 我也很累:
writeValues.Replace(writeValues, "");
WriteBox1.Text = writeValues;
嘗試在eventargs上設置Handled屬性。 將Handled設置為true可以取消KeyPress事件。 這樣可以避免控件處理按鍵。
例如:
private void keypressed(Object o, KeyPressEventArgs e)
{
// The keypressed method uses the KeyChar property to check
// whether the ENTER key is pressed.
// If the ENTER key is pressed, the Handled property is set to true,
// to indicate the event is handled.
if (e.KeyChar == (char)Keys.Return)
{
e.Handled = true;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.