G
Guest
In the .NET 2003 docs, it says to use the following code for an event handler
to determine which modifier key was pressed when an event is fired:
Private Sub Button1_KeyPress(ByVal sender As Object, ByVal e As _
System.Windows.Forms.KeyPressEventArgs) Handles Button1.KeyPress
If (Control.ModifierKeys And Keys.Shift) = Keys.Shift Then
MessageBox.Show("Pressed " & Keys.Shift)
End If
End Sub
My question: Why did MS elect to use a shared member of the Control class
(Control.ModifierKeys) instead of adding a member of the same name to the
KeyPressEventArgs class to hold this information for the time the event was
fired? To me, this approach would have been more encapsulated. More
importantly, won't Control.ModifierKeys hold incorrect information if the
user changes the state of Control.ModifierKeys before the event handler
fires? Unlikely sure, but I would think it is possible.
Any insight would be appreciated.
Thanks!
SolarCoder
to determine which modifier key was pressed when an event is fired:
Private Sub Button1_KeyPress(ByVal sender As Object, ByVal e As _
System.Windows.Forms.KeyPressEventArgs) Handles Button1.KeyPress
If (Control.ModifierKeys And Keys.Shift) = Keys.Shift Then
MessageBox.Show("Pressed " & Keys.Shift)
End If
End Sub
My question: Why did MS elect to use a shared member of the Control class
(Control.ModifierKeys) instead of adding a member of the same name to the
KeyPressEventArgs class to hold this information for the time the event was
fired? To me, this approach would have been more encapsulated. More
importantly, won't Control.ModifierKeys hold incorrect information if the
user changes the state of Control.ModifierKeys before the event handler
fires? Unlikely sure, but I would think it is possible.
Any insight would be appreciated.
Thanks!
SolarCoder