Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1486
  • Last Modified:

Textbox beeping when pressing enter key, tried e.Handled=true but does not fix this!

Here the code snippet after trying hard to get rid of the beeping and removing \r\n key entry when multiline=true (as way of getting rid of the beep). Is there better way for entering numberic data into box than the textbox...it seem strange that textbox nor  richtextbox does not have event feature when entry is completed (via return key or unfocused). What is the best entry box in the world?.

Here the code snippets, I found it does not immediently generates beep until end of the program, is there way of disabling that but keep beep for other code?.

private void Agl_Set_Amp_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
            {
                  if (e.KeyCode==Keys.Enter)
                  {
                        e.Handled=true;                                    //will not work to remove the beep!
                        string datas=Agl_Set_Amp.Text.Trim();      //remove space
                        datas.Trim('\r');                                    //this will not work well since it won't remove it in the middle !! investigating alternative method.
                        datas.Trim('\n');
                        int datai=Tools.ConversionStringtoInterger(datas);  //contain try and exception trap (via interface) for non numberic data (System.Convert.Int32(string datas)).
                        if (datai==-975579)                                              //the chance of having same value is very very very tiny, hence use this as error...assumed!
                        {
                              double dataf=Math.Round(myAgl.VoltageAmp*1000);  //restore value if data invalid.
                              Agl_Set_Amp.Text=dataf.ToString();
                              Agl_Set_Amp.Refresh();
                              return;
                        }
                        else
                        {
                              double dataf = System.Convert.ToDouble(datai); //convert interger into float
                              myAgl.VoltageAmp=(float)(dataf/1000);            
                              myAgl.AglVert_F_Ampitude("SET");                   //Program instrument via interface protocol (seperates class).
                              myAgl.AglVert_F_Ampitude("GET");
                              myAgl.AglVert_F_Offset("GET");
                              AglOut_Refresh_Active_Channel_Display();        //Update display.
                        }
0
riscy
Asked:
riscy
  • 2
1 Solution
 
riscyAuthor Commented:
Note that the update display  AglOut_Refresh_Active_Channel_Display();  does not cause beep sound!
0
 
RomanPetrenkoCommented:
Put e.Handled=true into KeyPress Handler but not in KeyDown, because KeyPress cause this annoying beep.
====sample===
private void Form1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
  if (e.KeyChar == 0x0d) //Enter key pressed
  {
    if (this.ActiveControl is TextBox) //don't beep only for textbox
      e.Handled = true;
  }
}
====end of sample===
0
 
riscyAuthor Commented:
Thank that seem to fix problem...only from the keypress event.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now