![](/img/trans.png)
[英]How can I use the DevExpress WinForms TextEdit as a password entry (with asterisks)?
[英]How i change custom input in TextEdit Devexpress
我有屬性最大值為6的TextEdit,默認值為“ 000000”,我將根據用戶輸入替換該值。 例如,當用戶在TextEdit中輸入“ 69”時,TextEdit的最終值為“ 000069”。 我如何使用C#准備呢?
請幫我准備一下...
在TextEdit控件上使用“編輯蒙版”。 若要實現所需的功能,可以將TextEdit.Properties.Mask.MaskType屬性設置為Simple ,並將TextEdit.Properties.Mask.EditMask屬性設置為“ 000000”。
查看文檔- 遮罩編輯器概述
要啟用簡單屏蔽模式,請將RepositoryItemTextEdit.Mask對象的MaskProperties.MaskType屬性設置為MaskType.Simple 。 掩碼本身應通過MaskProperties.EditMask屬性指定。
例:
textEdit1.Properties.Mask.EditMask = "000000";
textEdit1.Properties.Mask.UseMaskAsDisplayFormat = true;
textEdit1.Properties.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.Simple;
如果您不想掩蓋編輯器控件,請使用Formatting ,這是一個示例:
如何:將自定義文本添加到格式化的字符串
textEdit1.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
textEdit1.Properties.DisplayFormat.FormatString = "{0:d6}";
希望這個幫助
嘗試以下操作(將EditValueChanging事件處理程序添加到文本編輯中):
private void textEdit_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
{
const int MaxLength = 6;
var editor = (DevExpress.XtraEditors.TextEdit)sender;
if (e.NewValue != null)
{
var s = (string)e.NewValue;
s = s.TrimStart('0');
if (string.IsNullOrWhiteSpace(s) == false)
{
BeginInvoke(new MethodInvoker(delegate
{
editor.Text = s.Substring(0, Math.Min(s.Length, MaxLength)).PadLeft(MaxLength, '0');
editor.SelectionStart = MaxLength;
}));
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.