c# Avoid beep on KeyDown press? - audio

I'm having a problem removing the beep sound when pressing the Enter key in a textbox.
This doesn't work:
private void textBox3_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
e.SuppressKeyPress = true;
button1.PerformClick();
}
}

I found an answer!
private void textBox2_KeyDown(object sender, KeyEventArgs e)
{
//Pressing ENTER
if (e.KeyCode == Keys.Enter)
{
button1.Select();
e.SuppressKeyPress = true;
SendKeys.Send("{ENTER}");
}
}

Related

RichEditBox How to know Which line the cursor is in

How can i know If user click Enter in keyboard in RichEditBox?
this code does not work
private void Editor_KeyDown(object sender, KeyRoutedEventArgs e)
{
var dia = new MessageDialog(e.Key + "");
dia.ShowAsync();
}
also This code does not work
private void Editor_KeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.OriginalKey == (VirtualKey)(char)13)
{
NumberEditor.Text += Convert.ToString(_LineNum) + Environment.NewLine;
++_LineNum;
}
}
How can i get line of row in RichEditBox and how can i change text from code in RichEditBox?
I want to make an Editor and any help is appreciated.
Regards
Look this method:
private void ChangeLine()
{
var textRange = MyRichEditBox.Document.GetRange(MyRichEditBox.Document.Selection.StartPosition, MyRichEditBox.Document.Selection.StartPosition);
textRange.Expand(TextRangeUnit.Line);
//Change line size.
textRange.CharacterFormat.Size = 30;
//Center the paragraph
textRange.ParagraphFormat.Alignment = ParagraphAlignment.Center;
//this will change text of the range
textRange.Text = "My new text";
}
From Document you have to get ITextRange. After that you can expand it to TextRangeUnit.Line and get whole line. Now you can change the style and text of the line.
Try this code for KeyDownEvent:
public sealed partial class TextEditPage : Page
{
private readonly KeyEventHandler _keyDownHandler;
//Constructor
public TextEditPage()
{
this.InitializeComponent();
this.Unloaded += OnUnloaded;
//Add keydown event
this._keyDownHandler = OnKeyDown;
RtfBox.AddHandler(KeyDownEvent, this._keyDownHandler, true);
}
private void OnKeyDown(KeyRoutedEventArgs e)
{
//enter your code here
}
private void OnUnloaded(object sender, RoutedEventArgs routedEventArgs)
{
this.RemoveHandler(KeyDownEvent, _keyDownHandler);
}
}
Don't forget to remove handler in Unloaded.

I'm new to c# but what is wrong here

private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (this.m_keyCode == Keys.Enter)
{
webBrowser1.Navigate(textBox1.Text);
}

Hide keyboard when a specific number of digit has entered on editText

Goal:
When ever 6 digit entered on ID_Display, It would hide the keyboard.
Problem:
Keyboard wouldnt hide unless Keyboard "Enter" is press
public void keyboard_hide_Listener() {
ID_Display = (EditText) findViewById(R.id.ID_display);
if (ID_Display != null) {ID_Display.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (event != null && (ID_Display.getText().length()>=6)) { //event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
System.out.println("Edit Text Length: " +ID_Display.getText().length());
in.hideSoftInputFromWindow(ID_Display.getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
return true;
}
return false;
}
});
}
}
(ID_Display.getText().length()>=6
You should probably go with v.GetText() instead of ID_display

textbox sends enter key for each number entered

Im using a textbox to accept barcode input and then the enter key to do stuff with that input. But its sending the enter key once for each number entered. Is there a way to have the enter key sent only once? Or maybe supress the other enters?
private void txtBscanned_KeyDown(object sender, KeyEventArgs e)
{
this.txtBscanned.KeyDown += new System.Windows.Forms.KeyEventHandler(this.OnKeyDownHandler);
}
private void OnKeyDownHandler(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
MessageBox.Show(txtBscanned.Text);
}
}
Why are you assigning a keydown event on the textbox itself? You should assign the event on the constructor or using the designer.
public Form1()
{
InitializeComponent();
txtBscanned.KeyDown += new KeyEventHandler(this.OnKeyDownHandler);
}

How to create Right Click and Middle Click event on custom hyperlink button?

I am creating my Custom hyperlink button deriving from Silverlight HyperlinkButton I want to create Right Click and Middle click event on it. Can some help me please.
Thanks,
Gobind
I would add a couple of events (like MiddleClick and RightClick), then handle the MouseUp (or MouseDown, if you want to intercept on the down), then fire one of the two events depending on the details of the MouseUp event. For example:
public MyControl()
{
InitializeComponent();
MouseUp += OnMouseUp;
}
void OnMouseUp(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Middle)
{
OnMiddleClick(e);
e.Handled = true;
return;
}
if (e.ChangedButton == MouseButton.Right)
{
OnRightClick(e);
e.Handled = true;
return;
}
}
public event MouseButtonEventHandler RightClick;
protected virtual void OnRightClick(MouseButtonEventArgs e)
{
var handler = RightClick;
if (handler != null) handler(this, e);
}
public event MouseButtonEventHandler MiddleClick;
protected virtual void OnMiddleClick(MouseButtonEventArgs e)
{
var handler = MiddleClick;
if (handler != null) handler(this, e);
}

Resources