Creating a KeyDown Event Handler for Label Management

I'm sure you all know that there is no KeyDown handler in Label Control (and why?) ... Anyway, I need a KeyDown handler for the Label control and appreciate any pointers / suggestions to get me started.

I searched but did not find any information on creating my own event handlers for the label control. Could this be C #?

thank

+3
source share
4 answers

In the constructor, I did the following:

SetStyle (ControlStyles.Selectable, true);

and also override the OnMouseDown method:

protected override void OnMouseDown(MouseEventArgs e)
{
  base.OnMouseDown(e);
  if (this.CanSelect) this.Select();
}

. TextBox , ...

+1

. . KeyDown.

- , TextBox :

textBox1.BorderStyle = BorderStyle.None;
textBox1.Cursor = Cursors.Default;
textBox1.ReadOnly = true;
textBox1.TabStop = false;
textBox1.Text = "foo";

.

+2

, , Key *. , , , , .

, , , - .

+1
source

Actually, it Labelinherits from Control, so it has an event KeyDown. It’s just that Visual Studio doesn’t show it in the GUI, because it is Labelnot designed to receive focus, so the specified event usually does not fire.

0
source

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


All Articles