如何檢查用戶是否將NumericUpDown
控件留空,並刪除其值? 因此,我可以重新分配它的0檢查NumericUpDown是否爲空
5
A
回答
6
if(NumericUpDown1.Text == "")
{
// If the value in the numeric updown is an empty string, replace with 0.
NumericUpDown1.Text = "0";
}
0
decimal d = 0
if(decimal.TryParse(NumericUpDown1.Text, out d)
{
}
NumericUpDown1.Value = d;
4
值使用驗證的事件,並要求文本屬性
private void myNumericUpDown_Validated(object sender, EventArgs e)
{
if (myNumericUpDown.Text == "")
{
myNumericUpDown.Text = "0";
}
}
0
這可能是有用的試試這個
if (string.IsNullOrEmpty(((Control)this.nud1).Text))
{
//null
}
else
{
//have value
}
0
如果你w螞蟻禁止NumericUpDown
爲空值,只需使用這個類。其效果是,一旦用戶試圖通過全選+退格鍵刪除控制值,則實際數值將再次設置。這並不是一個煩惱,因爲用戶仍然可以通過select-all +鍵入數字數字開始編輯新的數值。
sealed class NumericUpDownEmptyValueForbidder {
internal NumericUpDownEmptyValueForbidder(NumericUpDown numericUpDown) {
Debug.Assert(numericUpDown != null);
m_NumericUpDown = numericUpDown;
m_NumericUpDown.MouseUp += delegate { Update(); };
m_NumericUpDown.KeyUp += delegate { Update(); };
m_NumericUpDown.ValueChanged += delegate { Update(); };
m_NumericUpDown.Enter += delegate { Update(); };
}
readonly NumericUpDown m_NumericUpDown;
string m_LastKnownValueText;
internal void Update() {
var text = m_NumericUpDown.Text;
if (text.Length == 0) {
if (!string.IsNullOrEmpty(m_LastKnownValueText)) {
m_NumericUpDown.Text = m_LastKnownValueText;
}
return;
}
Debug.Assert(text.Length > 0);
m_LastKnownValueText = text;
}
}
相關問題
- 1. 檢查NumericUpDown是否沒有值
- 2. 檢查dataGridView是否爲空
- 3. 檢查JValue是否爲空
- 4. 檢查imageView是否爲空
- 5. 檢查tabControl1是否爲空?
- 6. 檢查CSV是否爲空
- 7. 檢查double是否爲空
- 8. 檢查列是否爲空
- 9. 檢查ALAssetsLibrary是否爲空
- 10. 檢查ArrayCollection是否爲空
- 11. laravel檢查是否爲空
- 12. 檢查textarea是否爲空
- 13. 檢查ImageSource是否爲空
- 14. 檢查是否爲空JasperReports
- 15. 檢查是否爲空JFormattedTextField
- 16. 檢查editText是否爲空
- 17. 檢查JTextField是否爲空
- 18. 檢查是否爲空VB.NET
- 19. 檢查StringBuffer是否爲空
- 20. 檢查OnAction是否爲空
- 21. 檢查NSDictionary是否爲空
- 22. 檢查JTextFields是否爲空
- 23. 檢查managedobjectcontext是否爲空?
- 24. 檢查它是否爲空
- 25. 檢查stderr是否爲空
- 26. 檢查NSRect是否爲空
- 27. 檢查DataView是否爲空
- 28. 檢查是否爲空DataRow
- 29. 檢查EditText是否爲空
- 30. 檢查TextView是否爲空?
檢查變量的長度 - http://www.dotnetperls.com/string-length – 2013-02-25 18:51:01