我的自定义NumericUpDown的值修整为100。我没有运气在网上搜索。例如,当我将“最大值”(Maximum)设置为90时,它很好用,但是当我将其设置为“ 130”时,该值被裁剪为100。
public class StrictNumericUpDown : NumericUpDown
{
[DefaultValue(120), Browsable(true),
EditorBrowsable(EditorBrowsableState.Always),
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public new int Maximum { get; set; }
[DefaultValue(0), Browsable(true), EditorBrowsable(EditorBrowsableState.Always), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public new int Minimum { get; set; }
protected override void OnTextBoxTextChanged(object source, EventArgs e)
{
base.OnTextBoxTextChanged(source, e);
if (Text == "")
{
Text = "0";
}
if (Value > Maximum)
{
Value = Maximum;
}
}
}