Keyboard (KeyDown/Up/Press/...) Events?

3 posts, 1 answers
  1. Jörg B.
    Jörg B. avatar
    8 posts
    Member since:
    Jul 2009

    Posted 28 Feb 2011 Link to this post

    Hello there,

    I had a quick look at the Silverlight documentation (is the WPF RichTextBox (beta) Documentation available already somewhere?) and I did not see any Events being mentioned regarding key events, as in e.g. whenever the user enters a key in the editor indicate what key(s) was/were pressed (or e.g. what combo like alt+shift+f etc). Is anything like that available/possible or planned for the editor?

    Best regards,
    -Jörg B.
  2. Answer
    Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 03 Mar 2011 Link to this post

    Hi Jörg B.,

    There is still not any documentation of the WPF version of RadRichTextBox, but you have guessed right that most of the things that are described in the documentation for the Silverlight control also apply to the WPF one.
    As for the Key events you have mentioned, RadRichTextBox inherits them from System.Windows.UIElement and should work just as they do for all WPF controls. Here is an example of how you can get the pressed Keys on KeyDown:

    Copy Code
    private void editor_KeyDown(object sender, KeyEventArgs e)
    {
        ModifierKeys modifiers = e.KeyboardDevice.Modifiers;
     
        if ((modifiers & ModifierKeys.Shift) != 0 && (modifiers & ModifierKeys.Control) != 0)
        {
            MessageBox.Show("Shift and Control are pressed!");
        }
        //if (modifiers.HasFlag(ModifierKeys.Shift) && modifiers.HasFlag(ModifierKeys.Control))
        //{
        //    MessageBox.Show("Shift and Control are pressed!");
        //}
    }

    I have listed two options and commented out the second. You can choose which one fits your taste better.

    Greetings,
    Iva
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. Jörg B.
    Jörg B. avatar
    8 posts
    Member since:
    Jul 2009

    Posted 03 Mar 2011 Link to this post

    Great to hear - thanks!
Back to Top