Search code examples
c#winformsfocuskeyup

Control lost focus


I have a form, and when I press a keyboard key over the form Key_Up event works fine, but when I press any button on ToolStrip, I lost Form forever and Key_Up event doesn't work anymore.

I want a solution that when I put the mouse pointer over PictureBox then give Form the focus, like VMware window.

private void frmMonitor_KeyUp(object sender, KeyEventArgs e)
{
     if (e.KeyValue == 18)
        return;
     pc.PacketSystem.Send_KeyBoardEventPacket(e.KeyValue.ToString());
}
private void picSnap_MouseMove(object sender, MouseEventArgs e)
{
     this.Focus();
}

enter image description here


Solution

  •  private void picSnap_MouseMove(object sender, MouseEventArgs e)
    {
                this.Activate();
                this.KeyPreview=true;
    }
    

    thanks, Roman