Lack of Assembly Reference C#

Asked

Viewed 38 times

0

I have an error of lack of use of Directive or a Assembly Reference aimed atKeyCodand Modifiers

Can anyone tell me what it would be and how I can carry it ?

    private void lblAutoCod_MouseClick(object sender, MouseEventArgs e)
    {
        if (e.KeyCode == Keys.C && e.Modifiers == Keys.Control)
        {

            MessageBox.Show("You pressed ctrl + c");
        }
    }

The purpose is to make who in a click on a label the text is copied.

Follows: Erro na prática

1 answer

5

You are confusing the event. The correct is KeyEventArgs. Not MouseEventArgs. Your code makes no sense.

If the goal is to test which button mouse was pressed, change the event to:

private void lblAutoCod_MouseClick(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        MessageBox.Show("Botão direito do mouse pressionado.");
    }
}
  • 1

    Exactly! I was just going to say that. What’s the point of trying to capture a key (from the keyboard) in an event fired when a mouse click occurs?

  • I know... it makes sense now. So maybe my reasoning isn’t getting where I really want to go. Maybe a completely different question would help me. Ex: In an Event Mouse_Click on top of a label, the texto of that Label be copied (as if I had given one CTRL+C in the texto label) ..

  • Yeah, better try another question.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.