At the end of the method it does this. "but.Location = new Point (x, y);".
The problem is that by pressing the directional arrow, it changes the location of the button and does not continue with the focus on the button it focuses on another button.
Member 11426986
Posts
-
Disable focus in button with arrow right left up down -
Disable focus in button with arrow right left up downI have a problem. When i press the arrow down, up, right or left with focus in a button, i want the button have moved for direction selected,
But this does not happen, another button is focused. I set TabStop of the button to false, but even so with the arrows still focuses other buttons.
Below is the code for creating the button, and the method for moving it.private void btnCreateNewButton_Click(object sender, EventArgs e)
{
Button button = new Button();
button.Text = "";
button.FlatStyle = FlatStyle.Popup;
button.Left = 30;
button.Top = 30;
button.Width = 10;
button.Height = 40;
button.TabIndex = 1;
button.TabStop = false;
button.Click += new EventHandler(button_Click);
button.MouseDown += new MouseEventHandler(cli_MouseDown);
button.MouseMove += new MouseEventHandler(cli_MouseMove);
button.PreviewKeyDown += new PreviewKeyDownEventHandler(cli_PreviewKeyDown);panel3.Controls.Add(button); }
private void cli_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
Button but = sender as Button;
if (butMensagem.Focused)
{
int x = but.Location.X;
int y = but.Location.Y;if (e.KeyCode == Keys.Right) { x += 1; } else if (e.KeyCode == Keys.Left) { x -= 1; } else if (e.KeyCode == Keys.Up) { y -= 1; } else if (e.KeyCode == Keys.Down) { y += 1; } but.Location = new Point(x, y); } else { } }