The correct answer is: B. KeyChar
The KeyChar
property of the e
parameter is used to determine the pressed key. It returns a character that represents the key that was pressed.
The Keypress
property returns a string that represents the key that was pressed. It includes the key code and the character code.
The Keychar
property is not a valid property.
The Key.Char
property is not a valid property.
Here is an example of how to use the KeyChar
property:
“`
using System;
using System.Windows.Forms;
public class Form1 : Form
{
public Form1()
{
InitializeComponent();
// Add a KeyDown event handler to the button.
Button button1.KeyDown += new KeyEventHandler(button1_KeyDown);
}
private void button1_KeyDown(object sender, KeyEventArgs e)
{
// Display the character that was pressed.
MessageBox.Show(e.KeyChar.ToString());
}
}
“`
When you press a key on the keyboard, the KeyDown
event is raised. The e
parameter of the KeyDown
event contains information about the key that was pressed. The KeyChar
property of the e
parameter returns the character that represents the key that was pressed. In the example above, the KeyChar
property is used to display the character that was pressed in a message box.