I decided it was a call, and it might let me know what Fluent is, so I coded the Fluent keyboard class. I donβt think that I follow all fluent language structures and rules, but it works.
Helper Extension Method
/// <summary> /// Provides a set of static (Shared in Visual Basic) methods for starting a fluent expression on a <see cref="System.Windows.Form.Control"/> object. /// </summary> public static class ControlExtensions { /// <summary> /// Starts a fluent expression that occurs when a key is pressed. /// </summary> /// <param name="control">The control on which the fluent keyboard expression is occuring.</param> /// <param name="keys">The key when it will happen.</param> /// <returns>A <see cref="KeyboardFluent"/> object that makes it possible to write a fluent expression.</returns> public static KeyboardFluent When(this Control control, Keys keys) { return new KeyboardFluent(control).When(keys); } }
Free class
Now i can enter
public partial class Form1 : Form { public Form1() { InitializeComponent(); this.When(Keys.F).With(Keys.Control).IsDown().Do((sender, e) => MessageBox.Show(e.KeyData.ToString())); } }
and it will display the message box only when Ctrl + F is not working.
Pierre-alain vigeant
source share