From e8fcb72fc21b30bde63e215f14efb7179ba0d8f1 Mon Sep 17 00:00:00 2001 From: heartacker Date: Fri, 22 Mar 2024 21:51:24 +0800 Subject: [PATCH] 1. fix OnFormatChange 2. support bin 3. update hex input logic --- .../NumericUpDown/NumericUpDownBase.cs | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs b/src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs index 33f496b..ac846cb 100644 --- a/src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs +++ b/src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs @@ -176,7 +176,7 @@ public abstract class NumericUpDown : TemplatedControl, IClearControl { if (IsInitialized) { - SyncTextAndValue(false, null); + SyncTextAndValue(false, null, true);//sync text update while OnFormatChange } } @@ -343,7 +343,11 @@ public abstract class NumericUpDownBase : NumericUpDown where T : struct, ICo 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); } @@ -351,10 +355,21 @@ public abstract class NumericUpDownBase : NumericUpDown where T : struct, ICo { 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); } + 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;