This is a migrated thread and some comments may be shown as answers.

Derive from RadTextBox

9 Answers 140 Views
TextBox
This is a migrated thread and some comments may be shown as answers.
Silviu
Top achievements
Rank 1
Silviu asked on 03 Sep 2008, 07:20 AM
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");
        }

    }

9 Answers, 1 is accepted

Sort by
0
Angel
Telerik team
answered on 03 Sep 2008, 04:20 PM
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.
0
Silviu
Top achievements
Rank 1
answered on 04 Sep 2008, 02:55 AM
I did try that, but the event still won't fire. Does it work for you?
0
Angel
Telerik team
answered on 04 Sep 2008, 01:27 PM
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.
0
Wojciech
Top achievements
Rank 2
answered on 16 Jul 2010, 09:25 AM
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
0
Stefan
Telerik team
answered on 20 Jul 2010, 05:57 PM
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
0
Rowen
Top achievements
Rank 1
answered on 22 Mar 2012, 06:54 AM
Has this issue been fixed yet? I am trying to override onkeypress in a class derived from RadTextBox and my override is never triggered.
0
Stefan
Telerik team
answered on 26 Mar 2012, 04:30 PM
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 >>
0
Mohsen
Top achievements
Rank 1
answered on 31 Jan 2013, 04:05 PM
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.
0
Stefan
Telerik team
answered on 01 Feb 2013, 10:46 AM
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.
Tags
TextBox
Asked by
Silviu
Top achievements
Rank 1
Answers by
Angel
Telerik team
Silviu
Top achievements
Rank 1
Wojciech
Top achievements
Rank 2
Stefan
Telerik team
Rowen
Top achievements
Rank 1
Mohsen
Top achievements
Rank 1
Share this question
or