Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Allow only digits and the "."-char in AxCWNumEdit input mode

Hi,

I'm a beginner working with Measurement Studio 7.1 under Visual Basic .NET 2003 and I have the following problem:

In AxCWNumEdit (Mode: cweModeControl) I want to allow only the digits 0 to 9 and the "." char for input. Which event I have to implement? It's not the keypress- or keydown-event I guess.

Thank you in advance
Christian W.
0 Kudos
Message 1 of 9
(4,452 Views)
Since you're using Measurement Studio 7.1 and Visual Basic .NET, is there a reason that you're using the CWNumEdit ActiveX control via COM-interop instead of the Measurement Studio native .NET Windows Forms NumericEdit control? NumericEdit is a new control in Measurement Studio 7.1 and provides a much nicer development experience in .NET than CWNumEdit and has features that are not provided by CWNumEdit. NumericEdit has a FormatMode property whose type is NumericFormatMode, which is a type that controls the parsing, formatting, and validation of the NumericEdit's value. The default value of this property is a simple double mode which behaves exactly as you describe. The only change that you have to make to enable this behavior is to change the NumericEdit.ValidationMode property to WhenChanged, which will validate the value as it changes instead of when it's committed.

If you still want to use CWNumEdit, it can be done, but there's not an easy way to do it. You have to get the window handle to the edit control of the CWNumEdit and use Win32 subclassing to handle the WM_CHAR message to specify that the message must not be processed for the characters that you want to disallow.

- Elton
0 Kudos
Message 2 of 9
(4,438 Views)
Hello Elton,

thank you for the quick answer.

The reason why I'm using CWNumEdit instead of the Windows Forms NumericEdit is quite simple:

I use it (16 times of course) to set a 16-Channel Voltage/Current-Calibrator (Mode: Control) and - vice versa - to read (also 16 times) from the answering system (Mode: Indicator). In this case, I don't need the Inc/Dec-Buttons. Tell me, if I'm be incorrect, but I can deactivate the Inc/Dec-Buttons only in CWNumEdit.

I'll try to implement Win32 subclassing and hope it'll work.

Thank you very much,
Christian W.

Message Edited by TheSolid on 04-12-2005 12:47 AM

0 Kudos
Message 3 of 9
(4,433 Views)
The NumericEdit control that Elton is referring to is one of the new Measurement Studio controls that provides the same functionality as the CWNumedit. But this is a native .NET control, so you don't have to deal with ActiveX interop when using this. This is included with Measurement Studio 7.1.

If you want to remove the Inc/Dec buttons, you can change the interaction mode in the property grid to be only Text. If you de-select all the interaction modes, the control will be an indicator. Check out the NumEdit control in the .NET User Gallery.

If you have installed Measurement Studio 7.1 for Visual Studio 2003, you should have the .NET native controls show up in the toolbar under the Measurement Studio .NET Tools tab.

I hope this helps.
Bilal Durrani
NI
0 Kudos
Message 4 of 9
(4,422 Views)
Thank you Bilal,

that was it 🙂

A finally question about (native .NET) NumericEdit control:

To align text in horizontal position is no problem (property TextAlign). Is it also possible to align text in vertical position (special: to center the text) ?

Thank you very much,
Christian W.
0 Kudos
Message 5 of 9
(4,415 Views)
The numeric edit control's height is based on the font size and font of the text. So in effect, the text is always vertically centered for you. You can change the lenght of the numeric edit control arbitrarily. To change the height of the control, change the font size of the text.
Bilal Durrani
NI
0 Kudos
Message 6 of 9
(4,406 Views)
Hello Bilal,

I have compared the AxCWNumEdit and the NumericEdit (see Picture 9 KB).

You see my problem. If the font size is large, the text isn't "really" vertically centered (only in case of AxCWNumEdit - by fitting the lower border - it is really "centered").

Christian W.
0 Kudos
Message 7 of 9
(4,402 Views)
You will notice the same thing with the numericUpDown control and the textbox control. Based on the font you select, you will notice cases like this with these other controls as well. The NumericEdit control is based off of the numericUpDown control and we rely on its sizing algorithm for the sizing of the control.

You might try using another type of font and see if you get the same effect with this.

I hope this helps
Bilal Durrani
NI
0 Kudos
Message 8 of 9
(4,391 Views)
Hello Bilal,

thank you for your patience.

If I use another type of font I get the same effect. But it doesn't matter, I'll live with this "optical error" 🙂

Best regards,
Christian W.
0 Kudos
Message 9 of 9
(4,382 Views)