簡體   English   中英

如何替換文本框插入符號

[英]How to replace the TextBox Caret

我有一個用手機號碼綁定的文本框,並且-在每3個字符之后。例如,手機號碼的最大字符將為10,而在3個字符后-將顯示(例如,我有1234567890)(此手機號碼將被替換與123-456-7890)。

我的問題是我需要從文本框中刪除它,並將其設為空。任何人都可以幫我解決這個問題。這都是用C#完成的。這是我嘗試過的代碼。

這是我設置的關聯屬性

public static readonly DependencyProperty AssociatedElementProperty = DependencyProperty.Register("AssociatedElement", typeof(FrameworkElement), typeof(NumericKeyBoard), null);

this.caretPosition = associatedTextBox.SelectionStart;
if (associatedTextBox.Tag.ToString() == "mobile" && associatedTextBox.Text.Substring(this.caretPosition - 1, 1) == "-")
{
     associatedTextBox.Text = associatedTextBox.Text.Remove(this.caretPosition - 1, 1);
     this.caretPosition--;
}  

考慮使用經過修改的TextBox控件,例如MaskedTextBox

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM