Développer Réduire
Ce sujet n'a pas encore été évalué - Évaluez ce sujet

KeyStates, énumération

Specifies constants that define the state of a key.

Cette énumération possède un attribut FlagsAttribute qui permet la combinaison d'opérations de bits de ses valeurs membres.

Espace de noms: System.Windows.Input
Assembly : PresentationCore (dans presentationcore.dll)
Espace de noms XML :  http://schemas.microsoft.com/winfx/2006/xaml/presentation

[FlagsAttribute] 
public enum KeyStates : byte
/** @attribute FlagsAttribute() */ 
public enum KeyStates
FlagsAttribute 
public enum KeyStates
<propriété d'objet="ValeurÉnumération" .../>
 Nom de membreDescription
DownThe key is pressed. 
NoneThe key is not pressed. 
ToggledThe key is toggled. 

The KeyStates class is a bit field enumeration. Therefore, a key can be in multiple states. For example, a key could be in the Down state as well as in the Toggled state. Use bit operations to determine the exact state or states the key is in.

The following example changes the color of a Button if the KeyStates of the key passed in the KeyEventArgs is Down. The state of the key is determined by using a bitwise AND operation. The same technique can be used to determine whether a key has multiple states, such as being in the Toggled state and the Down state.

// A bitwise AND operation is used in the comparison.
// e is an instance of KeyEventArgs.
// btnDown is a Button.
if ((e.KeyStates & KeyStates.Down) > 0)
{
    btnDown.Background = Brushes.Red;
}

Microsoft .NET Framework 3.0 est pris en charge sur Windows Vista, Microsoft Windows XP SP2 et Windows Server 2003 SP1.

.NET Framework

Prise en charge dans : 3.0
Cela vous a-t-il été utile ?
(1500 caractères restants)

Ajouts de la communauté

AJOUTER
© 2013 Microsoft. Tous droits réservés.