Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

NumericEdit beeps when pressing enter

Solved!
Go to solution

When using a numberic edit and typing in a number followed by the "Enter" key the sound card will beep.  Is there a way to prevent this behavior?

0 Kudos
Message 1 of 6
(4,422 Views)

UmmGooD,

 

What do you mean by a numeric edit?  Where/how are you getting this item?

Sincerely,
Jason Daming
Applications Engineer
National Instruments
http://www.ni.com/support
0 Kudos
Message 2 of 6
(4,406 Views)

It is the NumericEdit control available in Measurement Studio.  When a user types in a number then presses enter the control will cause a 'Beep' which has received complaints from customers.  I would like to figure out a way to stop this behavior.

 

Here is the full name:

NationalInstruments.UI.WindowsForms.NumericEdit

0 Kudos
Message 3 of 6
(4,400 Views)

UmmGooD,

 

This is not a Measurement Studio thing it is a Visual Studio problem.  Basically the beep for pressing the enter button is because you have not configured an Accept Button or a button to take the default enter action.  The simplest way to "fix" this is to drop down a button set visible to False (or just use a button you already have).  Now go to your forms properties and set this button as the accept button.  If you are looking for a much more "complete" solution including handling the ESC key I would recommend you check out this external forum.

Sincerely,
Jason Daming
Applications Engineer
National Instruments
http://www.ni.com/support
0 Kudos
Message 4 of 6
(4,386 Views)
Sorry this took me so long but I finally tried this out.  Yes your solution gets rid of the beep but now when pressing enter in the numeric edit the AfterChangeValue event handler no longer gets called.  Even if I change focus out of the numeric edit my event handler method never gets called correctly.
0 Kudos
Message 5 of 6
(4,301 Views)
Solution
Accepted by topic author UmmGooD

Hi UmmGooD,

 

When you configure an Accept button for the form, the enter button will be handled by the form to raise the Accept button's event handler. The Value in the NumericEdit is not updated and  hence the AfterChangeValue is not raised. But changing focus out of the NumericEdit after changing the value should raise the AfterChangeValue event.

 

Another way to remove the beep without the above disadvantage is by creating an event handler for the keypress event on the NumericEdit and setting the Handled value of the KeyPressEventArgs to true when 'Enter' is pressed.

 

private void NumericEdit1_KeyPress(object sender, KeyPressEventArgs e)

{
    // Form has no AcceptButton - prevents default beep on hitting enter
     if (e.KeyChar == 13)
    {
        e.Handled = true;
    }
}

Thanks,
Mohammed Haseeb|Measurement Studio|National Instruments
0 Kudos
Message 6 of 6
(4,277 Views)