Press Enter to click LinkLabel

If I have linklabel in .net winform, is there anyway when the link label is focused, press a key enterto trigger a click LinkLabel?

Unfortunately, this is not like an event KeyDown.


EDIT

The easiest solution is to use PreviewKeyDownif something happens here with Google.

+3
source share
2 answers

You can create your own link shortcut class that extends LinkLabel and overrides the OnKeyUp or OnKeyDown event to capture the ENTER key press.

This will allow you to reproduce the code for each link label added to your form.

eg.

public class LinkLabelEx : LinkLabel
{

    protected override void OnKeyUp(KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
        {
            e.SuppressKeyPress = true;
            e.Handled = true;
            OnLinkClicked(new LinkLabelLinkClickedEventArgs(new Link(0, this.Text.Length)));
        }
        else
        {
            base.OnKeyUp(e);
        }
    }

}
+2
source

, LinkLabel click. keyDown .

0

Source: https://habr.com/ru/post/1796159/


All Articles