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
'nnn00' is one of the most appropriate mask, to work along with the Spin Increment where numbers can be entered from right to left and no empty place holders are kept in between for missing numbers.
Having # or 9 in place of n, keep empty spaces as place holders for digits and numbers are entered from left to right which makes it hard to spin increment and type in values.
I will also be enquiring more on this and will update you if I have a better answer.
One option, is to use the same Numeric Editor and validate the value user enters and round it to the nearest 100's. For that all you need to do is update the ultraNumericEditor1_ValueChanged event with one line of code as,
private void ultraNumericEditor1_ValueChanged( object sender, EventArgs e ){ if( ultraNumericEditor1 != null ) { int nValue = SaveObject2Int32(ultraNumericEditor1.Value); f (nValue > 0) { DebugWriteLine(nValue.ToString()); } ultraNumericEditor1.Value = Math.Round(nValue / 100d, 0) * 100; }}
Thanks,Josheela
Frank
I am attaching a sample with the solution.
Thanks
Hi Josheela,
Thank you very much for your example.
While testing the example I found to things. The two ending zeros are vertically misaligned and do have a different color color when they are selected compared to the other numbers.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 again.
Thank you 1000 times!
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.
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.
Hi 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 Mike,
I changed the replacement character to an 'o' and checked it quickly on three different virtual machines. It is now more than good enough.
Thank you very much indeed for your worthful helping!
Regards Frank
I think that will be extremely difficult. I think the problem is that the measurement of the text is measuring the actual text of the character and then you are drawing a different character. You could try changing the replacement character to some other character and if you are lucky, you might find a character that has exactly the same width as the '0' which is being drawn. But whether there is such a character and whether that will work on all machines is something I can't be sure of.
Another approach you could take is drawing both 0s at once. So what you would have to do in that case is that you would not draw the 0's inside the DisplayCharUIElement - you just do nothing in the DrawFilter for those elements so they draw nothing. Then you would have to use the DrawFilter to draw a string of "00" on the parent element. The challenge in that case would be lining up the 0's with the last digit before the 0. I'm not sure if that will actually work any better.
Frankly, if it were me, I would just remove the 0's from the MaskedEditor entirely and then put some text in a label that says "Hundreds of x's" or something like that. Not ideal from the UI perspective, but a lot easier to implement. :)
I have attached the sample with the changings.
Your recommendation with the ButtonsRight collection does work well. The last thing for a perfect solution would be closings the gap between the two last zeros. Is there a possibility to adjust the DrawFilter in that way that the gap can be closed?
I am completely aware that we shoot a little bit over the target of the normal behavior of the UltraEditMask. The end user does not really understand that we are facing a lot of pain solving his “simple” demand of stepping in increments +/-100.
Thank you so much for your help.
Actually... I take that back. There is a way to do it. :)
You could turn off the built-in spin buttons and then add your own using the ButtonsRight collection:
this.ultraMaskedEdit1.SpinButtonDisplayStyle = Infragistics.Win.SpinButtonDisplayStyle.None; this.ultraMaskedEdit1.ButtonsRight.Add(new SpinEditorButton()); this.ultraMaskedEdit1.EditorSpinButtonClick += UltraMaskedEdit1_EditorSpinButtonClick;
But then you have to handle the incrementing/decrementing of the values yourself in code:
private void UltraMaskedEdit1_EditorSpinButtonClick(object sender, SpinButtonClickEventArgs e) { string text = this.ultraMaskedEdit1.GetText(Infragistics.Win.UltraWinMaskedEdit.MaskMode.Raw); int initialValue = 0; if (false == string.IsNullOrEmpty(text)) initialValue = int.Parse(text); switch (e.ButtonType) { case SpinButtonItem.NextItem: this.ultraMaskedEdit1.Value = initialValue + 1; break; case SpinButtonItem.PreviousItem: this.ultraMaskedEdit1.Value = initialValue - 1; break; } }
private void UltraMaskedEdit1_EditorSpinButtonClick(object sender, SpinButtonClickEventArgs e) { string text = this.ultraMaskedEdit1.GetText(Infragistics.Win.UltraWinMaskedEdit.MaskMode.Raw); int initialValue = 0; if (false == string.IsNullOrEmpty(text)) initialValue = int.Parse(text);
switch (e.ButtonType) { case SpinButtonItem.NextItem: this.ultraMaskedEdit1.Value = initialValue + 1; break; case SpinButtonItem.PreviousItem: this.ultraMaskedEdit1.Value = initialValue - 1; break; } }