Edit

KeysConverter Class

Definition

Provides a TypeConverter to convert Keys objects to and from other representations.

public ref class KeysConverter : System::ComponentModel::TypeConverter, System::Collections::IComparer
public class KeysConverter : System.ComponentModel.TypeConverter, System.Collections.IComparer
type KeysConverter = class
    inherit TypeConverter
    interface IComparer
Public Class KeysConverter
Inherits TypeConverter
Implements IComparer
Inheritance
KeysConverter
Implements

Examples

The following code example demonstrates how to use the KeysConverter class to convert a KeyCode to a String. This example assumes that you have a TextBox named TextBox1 on a Form named Form1.

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.KeyPressWork);
        this.textBox1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.KeyDownWork);
    }

    private void KeyDownWork(object sender, KeyEventArgs e)
    {
        MessageBox.Show(e.KeyCode.ToString(), "KeyDown");

        KeysConverter kc = new KeysConverter();
        MessageBox.Show(kc.ConvertToString(e.KeyCode), "KeyDown");
    }

    private void KeyPressWork(object sender, KeyPressEventArgs e)
    {
        MessageBox.Show(e.KeyChar.ToString(), "KeyPress");
    }
}
Public Class Form1
    Public Shared Sub Main()
    End Sub

    Private Sub KeyDownWork(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) _
        Handles TextBox1.KeyDown

        MessageBox.Show(e.KeyCode, "KeyDown")

        MessageBox.Show(e.KeyCode.ToString(), "KeyDown")

        Dim kc As KeysConverter = New KeysConverter()
        MessageBox.Show(kc.ConvertToString(e.KeyCode), "KeyDown")
    End Sub


    Private Sub KeyPressWork(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) _
        Handles TextBox1.KeyPress

        MessageBox.Show(e.KeyChar, "KeyPress")
        MessageBox.Show(e.KeyChar.ToString(), "KeyPress")
    End Sub
End Class

Remarks

Most commonly, the KeysConverter type converter is used to convert Keys instances to and from their corresponding localized String representations.

Constructors

Name Description
KeysConverter()

Initializes an instance of the KeysConverter class.

Methods

Name Description
CanConvertFrom(ITypeDescriptorContext, Type)

Returns a value indicating whether this converter can convert an object in the specified source type to the native type of the converter using the specified context.

CanConvertTo(ITypeDescriptorContext, Type)

Returns a value indicating whether this converter can convert an object in the specified source type to the native type of the converter using the specified context.

Compare(Object, Object)

Compares two key values for equivalence.

ConvertFrom(ITypeDescriptorContext, CultureInfo, Object)

Converts the specified object to the converter's native type.

ConvertTo(ITypeDescriptorContext, CultureInfo, Object, Type)

Converts the specified object to the specified destination type.

GetStandardValues(ITypeDescriptorContext)

Returns a collection of standard values for the data type that this type converter is designed for when provided with a format context.

GetStandardValuesExclusive(ITypeDescriptorContext)

Determines if the list of standard values returned from GetStandardValues is an exclusive list using the specified ITypeDescriptorContext.

GetStandardValuesSupported(ITypeDescriptorContext)

Gets a value indicating whether this object supports a standard set of values that can be picked from a list.

Applies to

See also