如何在DevExpress/WinForms TextEdit組件中爲用戶輸入建立一個只有負值的遮罩?只有負數的面具
我試圖做到這一點,但沒有成功:
Same question here, but this solution is not working
我認爲這是一個錯誤。
如何在DevExpress/WinForms TextEdit組件中爲用戶輸入建立一個只有負值的遮罩?只有負數的面具
我試圖做到這一點,但沒有成功:
Same question here, but this solution is not working
我認爲這是一個錯誤。
如果用數字的工作,我建議你使用SpinEdit。要限制它只接受負數,請使用RepositoryItemSpinEdit.MaxValue和RepositoryItemSpinEdit.MinValue屬性。
spinEdit1.Properties.MaxValue = -1;
spinEdit1.Properties.MinValue = decimal.MinValue;
如果您需要TextEdit,我建議您使用Abdellah的面具。因此,您將TextEdit.EditValue作爲數字而不是字符串,請使用ParseEditValue事件。
textEdit1.Properties.Mask.EditMask = "-[0-9]*[.]{0,1}[0-9]*";
textEdit1.Properties.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.RegEx;
private void textEdit1_ParseEditValue(object sender, DevExpress.XtraEditors.Controls.ConvertEditValueEventArgs e) {
if (e.Value is string) {
e.Value = double.Parse(e.Value.ToString());
e.Handled = true;
}
}
有沒有辦法用textedit上的面具來做到這一點? (沒有黑客) –
在這種情況下,我認爲阿卜杜拉的面具是最合適的。我修改了我的答案,以包含一個附加解決方案。 –
爲什麼SpinEdit不適合你? –
嘗試這種解決方案:
在您的形式負載:
TextEdit1.Properties.Mask.EditMask = "-#0.0000";
TextEdit1.Properties.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.Numeric;
TextEdit1.Properties.Mask.UseMaskAsDisplayFormat = false;
TextEdit1.Properties.EditFormat.FormatString = "-#0.0000";
而且韓德爾你的文字編輯的 「CustomDisplayText
」 事件:
private void TextEdit1_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
{
if ((e.Value != null) && !e.Value.Equals(""))
{
e.DisplayText = Convert.ToDouble(e.Value).ToString("-#0.0000");
}
}
試試這個:
txtEdit.Properties.Mask.EditMask = "\\d-";
您使用的是哪個版本的DX?
如果您認爲這是一個錯誤*,您應該與DevEx交談,因爲我們無法對此做任何事情。但是,您已*在* DevEx論壇鏈接的帖子中閱讀了後續評論,並提供了備用解決方案,對嗎? –