We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

KeyPress in IntegerTextBox

I want to make an IntegerTextBox read only. But using the ReadOnly property disables all the nice color coding (Red for negative) I like. So I want to keep it ReadOnly = false, and ignore keystrokes. I tried to install a KeyPress handler, but it looks like NumberTextBoxBase ignores the e.Handled = true returned from my handler. How can I achieve this?

3 Replies

AD Administrator Syncfusion Team April 4, 2005 04:30 PM UTC

Hi Paul, IntegerTextBox handles the keyboard input in it''s OnKeyPress method. So you''ll want to extend IntegerTextBox and override OnKeyPress as demonstrated by the following code snippet: public class ReadOnlyIntegerTextBox : IntegerTextBox { public ReadOnlyIntegerTextBox() : base() { } protected override void OnKeyPress(KeyPressEventArgs e) { return; } } This will prevent OnKeyPress from doing anything. Please let me know if you have any further questions on this subject. Regards, Gregory Austin Syncfusion Inc.


PA Paul April 5, 2005 03:19 PM UTC

I did what you said. My OnKeyPress does get called, but the problem is the caller, NumberTextBoxBase:ProcessKeyEventArgs does not alter his behavior in any way, based on the outcome of OnKeyPress. The callback is just an aside, not a participant in outcome determination.


AD Administrator Syncfusion Team April 5, 2005 04:03 PM UTC

Hi Paul, May be overriding the ProcessCmdKey without calling the base class and returning true will give you the result you''re are looking for. Regards, Thomas

Loader.
Live Chat Icon For mobile
Up arrow icon