1. fix OnFormatChange

2. support bin
3. update hex input logic
This commit is contained in:
heartacker
2024-03-22 21:51:24 +08:00
parent fa33477f85
commit e8fcb72fc2

View File

@@ -176,7 +176,7 @@ public abstract class NumericUpDown : TemplatedControl, IClearControl
{ {
if (IsInitialized) if (IsInitialized)
{ {
SyncTextAndValue(false, null); SyncTextAndValue(false, null, true);//sync text update while OnFormatChange
} }
} }
@@ -343,7 +343,11 @@ public abstract class NumericUpDownBase<T> : NumericUpDown where T : struct, ICo
if ((numberStyles & NumberStyles.AllowHexSpecifier) != 0) if ((numberStyles & NumberStyles.AllowHexSpecifier) != 0)
{ {
if (text.StartsWith("0X") || text.StartsWith("0x")) // support 0x hex while user input if (text.StartsWith("0x") || text.StartsWith("0X")) // support 0x hex while user input
{
text = text.Substring(2);
}
else if (text.StartsWith("h'") || text.StartsWith("H'")) // support verilog hex while user input
{ {
text = text.Substring(2); text = text.Substring(2);
} }
@@ -351,10 +355,21 @@ public abstract class NumericUpDownBase<T> : NumericUpDown where T : struct, ICo
{ {
text = text.Substring(1); text = text.Substring(1);
} }
else if (text.StartsWith("h'") || text.StartsWith("H'")) // support hex while user input }
else if (((int)numberStyles &/* NumberStyles.AllowBinarySpecifier */ 1027) != 0)
{
if (text.StartsWith("0b") || text.StartsWith("0B")) // support 0b bin while user input
{ {
text = text.Substring(2); text = text.Substring(2);
} }
else if (text.StartsWith("b'") || text.StartsWith("B'")) // support verilog bin while user input
{
text = text.Substring(2);
}
else if (text.StartsWith("b") || text.StartsWith("B")) // support bin while user input
{
text = text.Substring(1);
}
} }
return text; return text;