如何檢查用戶是否將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. 檢查JTextField是否爲空
- 2. 檢查stderr是否爲空
- 3. laravel檢查是否爲空
- 4. 檢查imageView是否爲空
- 5. 檢查表是否爲空
- 6. 檢查CheckedListBox是否爲空
- 7. 檢查JValue是否爲空
- 8. 檢查StringBuffer是否爲空
- 9. 檢查是否爲空DataRow
- 10. 檢查是否爲空VB.NET
- 11. 檢查ListView是否爲空
- 12. 檢查TextView是否爲空?
- 13. 檢查tabControl1是否爲空?
- 14. 檢查流是否爲空
- 15. 檢查它是否爲空
- 16. 檢查textarea是否爲空
- 17. 檢查innerHTML是否爲空
- 18. 檢查CSV是否爲空
- 19. 檢查std :: wstring是否爲空或空
- 20. 檢查列是否爲空或空
- 21. 檢查屬性是否存在與檢查是否爲空
- 22. ASP.NET檢查是否爲LoginName爲空
- 23. JQuery檢查輸入是否爲空而不是檢查onload?
- 24. mvc 4 IEnumerable檢查是否爲空
- 25. PHP檢查是否爲空字段
- 26. C++檢查文件是否爲空
- 27. 檢查對象是否爲空或NULL
- 28. 檢查字段是否爲空
- 29. Swift - 如何檢查TableView是否爲空
- 30. Tkinter檢查輸入框是否爲空
檢查變量的長度 - http://www.dotnetperls.com/string-length – 2013-02-25 18:51:01