Hello together!
I need to have a numerical editor which does cover the range from minimal 100 to maximal 15000 in steps of 100 with a spin button and as user entry over the keyboard.First I tried an UltraNumericEditor which is working fine, but the user can enter values like 12385. I found no input mask which forces the entry to xxx00.
Then I tried an UltraMaskedEdit and used an input mask ‘nnn00’. This works quite well, but if the user is typing in 15000 the UltraMaskedEdit shows only 1500. The problem with this mask is any occurrence of a zero in the user input.
So please has anybody a good idea for an input mask which is solving the demand?
I’m using: Infragistics4.Win.UltraWinMaskedEdit.v15.2 15.2.20152.2023I have attached a simple example which shows both controls.
Thank you very much for any suggestion!
RegardsFrank
Hi Frank,
Whew, I'm glad that worked, because I was out of ideas. :)
As for the spin buttons, I don't see any way to acheive that. The two zeroes in this case are literals and therefore they are not part of the number section. The spin buttons are enabled based on the context of where the caret is, and since literals can't spin, they get disabled.
The control really wasn't designed with this particular use case in mind, so even getting the two zeroes in there as literals that don't respond to the keyboard is quite a coup, in my opinion. But I think you've pretty much hit the limit of how far this approach can go.
Hi Mike,
Yes I can confirm that the new draw filter does align the last two characters on the same vertical position also with different DPI-Settings. I have tested it with DPI-Setting 125% and also 140%.
“If the caret is set between the two zeros the spin buttons are getting disabled and a spinning is not anymore possible. We need to set first the caret in the left hand side of the two zeros then the spin buttons are getting enabled.”
Is there also a simple trick that the spin buttons are still staying enabled?
Thank you very much indeed!
Regards Frank
I haven't been able to reproduce the issue, but the drawing code we sent you is very simple and doesn't really match what the control does when it draws the characters. So I have modified the DrawFilter to draw the text exactly how the control does it so it should match up with the rest of the characters. Please try this DrawFilter and let us know if that fixes the issue.
public class MaskedEditDrawFilter : IUIElementDrawFilter { public bool DrawElement(DrawPhase drawPhase, ref UIElementDrawParams drawParams) { Control control = drawParams.Element.Control; Font fontToDispose = drawParams.AppearanceData.CreateFont(control.Font); Font fontToDraw = fontToDispose ?? control.Font; StringFormat format = (StringFormat)StringFormat.GenericTypographic.Clone(); format.FormatFlags &= ~StringFormatFlags.FitBlackBox; CharacterRange[] ranges = new CharacterRange[1]; ranges[0] = new CharacterRange(0, 1); format.SetMeasurableCharacterRanges(ranges); format.FormatFlags &= ~StringFormatFlags.LineLimit; format.FormatFlags &= ~StringFormatFlags.NoWrap; format.FormatFlags = StringFormatFlags.NoClip; RectangleF rectInsideBorders = drawParams.ElementDrawingRectInsideBorders; try { format.FormatFlags |= StringFormatFlags.NoClip; DrawUtility.DrawString( drawParams.Graphics, "0", fontToDraw, (SolidBrush)drawParams.TextBrush, rectInsideBorders, format, GdiDrawStringFlags.GDIPlus); format.FormatFlags &= ~StringFormatFlags.NoClip; DrawUtility.DrawString( drawParams.Graphics, "0", fontToDraw, (SolidBrush)drawParams.TextBrush, rectInsideBorders, format, GdiDrawStringFlags.GDIPlus); } finally { if (null != fontToDispose) fontToDispose.Dispose(); } return true; } public DrawPhase GetPhasesToFilter(ref UIElementDrawParams drawParams) { var displayCharUIElement = drawParams.Element as DisplayCharUIElement; if (null != displayCharUIElement) { if (displayCharUIElement.DisplayChar.Char == Form1.replacementChar) { return DrawPhase.BeforeDrawForeground; } } return DrawPhase.None; } }
Hi Josheela,
Yes the screenshot is taken from your original sample. The cause of the misaligning is the machine running under windows 7 64Bit SP1 with a DPI-Setting more then 100%.I have tested the sample on another machine with a DPI-Setting to 100%, then it is correct aligned, but with 125% or 140% it is misaligned.
Thank you very much for your helping.
Is this screenshot from the sample I sent you? Because I don't see the misalignment in my sample. I am attaching a screenshot from my sample for reference.
You can set SelectedTextForeColor on the UltraMaskedEdit to ControlText to show all digits with the same color when selected.
The spinbutton behavior is the same as in your initial sample with the InputMask of 'nnn00' which makes digits on the 0nes and 10's place or the two leading digits to be 0 always.