C# prevent default action on a listbox control when the right or left arrow keys are pressed?

Try adding an event handler to the ListBox. KeyDown event. If the key pressed is an arrow key, set the Handled flag of the KeyPressEventArgs to true to prevent further processing.

Try adding an event handler to the ListBox. KeyDown event. If the key pressed is an arrow key, set the Handled flag of the KeyPressEventArgs to true to prevent further processing.

A code example, based on an MSDN Forum post private void listBox1_KeyDown(object sender, System.Windows.Forms. KeyEventArgs e) { If (e. KeyCode == Keys.

Right || e. KeyCode == Keys. Left) e.

Handled = true; }.

I believe that since these keys are considered System Key bindings, this will not work. I think you must use ProcessCmdKey – icemanind Jul 22 at 20:38 Yeah the default event action still occurs after the KeyDown method processes. I'll look into the processCmdKey method.

– Paul Jul 22 at 20:48 @Paul: Do you set the Handled flag to true to prevent further processing? – Anders Abel Jul 22 at 20:49 You're right Anders. That worked perfectly.My bad!

– Paul Jul 22 at 21:10.

You have to override the ProcessCmdKey method in the listbox control. Create a new class, derive it from listbox, then override the ProcessCmdKey.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions