Derive from RadTextBox

10 posts, 0 answers
  1. Silviu
    Silviu avatar
    5 posts
    Member since:
    Mar 2008

    Posted 03 Sep 2008 Link to this post

    Hello everyone!

    I am trying to create a derived class which inherits from RadTextBox. My reason for doing this: I want to override the OnKeyDown event. The code compiles, but the event never fires. What am I missing? Here's my code:

        public class MyTextBox:RadTextBox
        {
            protected override void OnKeyDown(KeyEventArgs e)
            {
                if (e.KeyCode == Keys.F1)
                    MessageBox.Show("test");
            }

        }

  2. Angel
    Admin
    Angel avatar
    121 posts

    Posted 03 Sep 2008 Link to this post

    Hello Silviu,

    When overriding OnKeyDown() you have to call the base method to call the event handlers. Your code should be like this:

    public class MyTextBox:RadTextBox  
    {  
        protected override void OnKeyDown(KeyEventArgs e)  
        {  
            if (e.KeyCode == Keys.F1)  
                MessageBox.Show("test");  
            // The event handlers will be called by the base method
            base.OnKeyDown(e);  
        }  


    Greetings,
    Angel
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Silviu
    Silviu avatar
    5 posts
    Member since:
    Mar 2008

    Posted 03 Sep 2008 Link to this post

    I did try that, but the event still won't fire. Does it work for you?
  5. Angel
    Admin
    Angel avatar
    121 posts

    Posted 04 Sep 2008 Link to this post

    Hi Silviu,

    The event is fired for sure. But I made tests with overriding and the override method is not called. This is an issue in our sources and it will be fixed for the next release.

    Thank you for bringing our attention to it, your points have been updated.
     

    All the best,
    Angel
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Wojciech
    Wojciech avatar
    4 posts
    Member since:
    Oct 2008

    Posted 16 Jul 2010 Link to this post

    Hi There

    Silviu's problem can be solved in this way:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Telerik.WinControls.UI;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Drawing;
     
    namespace Bsi.Controls.TelerikWinForms
    {
        public class MyTextBox : RadTextBox
        {
            public MyTextBox()
            {
                this.KeyDown += new KeyEventHandler(MyTextBox_KeyDown);
            }
     
            // This does not work :(
            protected override void OnKeyDown(KeyEventArgs e)
            {
                MessageBox.Show("Override OnKeyDown fires!");
                base.OnKeyDown(e);
            }
     
            // This works fine
            void MyTextBox_KeyDown(object sender, KeyEventArgs e)
            {
                MessageBox.Show("MyTextBox_KeyDown OnKeyDown fires!");
            }
     
            // Themes support
            public override string ThemeClassName
            {
                get
                {
                    return typeof(RadTextBox).FullName;
                }
            }
        }
    }

    I was wondering if override OnKeyDown problem is solved, but in Q3 2009 and Q2 2010 Trial the problem is present.
    (or I'm using override in wrong way :) ).

    Regards
    Wojciech Poniatowski
  7. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 20 Jul 2010 Link to this post

    Hi Wojciech,

    Thanks for writing.

    I have tested this with Q2 2010 and the KeyDown event is fired correctly on my end. Consider the next snippet:
     
    public Form1()
            {
                InitializeComponent();
                this.radTextBox1.KeyDown += new KeyEventHandler(radTextBox1_KeyDown);
            }
     
            void radTextBox1_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.F1)
     
                    MessageBox.Show("test");
            }

    I suppose now you don't need to override anything. 

    I hope this helps. If you need any further assistance, do not hesitate to contact us.

    Sincerely yours,
    Stefan
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Rowen
    Rowen avatar
    13 posts
    Member since:
    Aug 2008

    Posted 22 Mar 2012 Link to this post

    Has this issue been fixed yet? I am trying to override onkeypress in a class derived from RadTextBox and my override is never triggered.
  9. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 26 Mar 2012 Link to this post

    Hello Rowen,

    This issue is logged in our system, but it is not yet resolved. I am adding it to PITS, where you can add your vote for it: http://www.telerik.com/support/pits.aspx#/public/winforms/10458

    Meanwhile, you can subscribe to the KeyPress event when the text box is initialized and use this event instead.
     
    Greetings,
    Stefan
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  10. Mohsen
    Mohsen avatar
    13 posts
    Member since:
    Jan 2013

    Posted 31 Jan 2013 Link to this post

    Hi Stefan

    As shown in your link,the issue has been solved.So where is the hot fix?I use Telerik WinForms 2012 Q2.
    Regards,
    Mohsen.
  11. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 01 Feb 2013 Link to this post

    Hello Mohsen,

    Thank you for writing.

    The issue is resolved in Q3 2012, so I will suggest that you upgrade your project to the latest version in order to take advantage of this and many other fixes and improvements.

    I will check why the PITS item was not updated accordingly. Please excuse us for the inconvenience.
     
    All the best,
    Stefan
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Back to Top
UI for WinForms is Visual Studio 2017 Ready