Overriding WndProc in custom TextBox

  • Thread starter Thread starter PeterB
  • Start date Start date
P

PeterB

Hi!

I'm trying to override WndProc( ref Message m) in my custom TextBox control.
Unfortunately it seems like the System.Windows.Forms.Message class is not
available in CF. Is there a was to reference this class anyway?

I tried referencing Microsoft.WindowsCE.Forms but I get the following
compile error:
WndProc(ref Microsoft.WindowsCE.Forms.Message)': no suitable method found to
override

I am not sure whether it is impossible to override the WndProc method in
this context or if I'm just using the wrong Message definition.

Ideas?

Thanks!

/ Peter
 
Well... it's not an application, so using ApplicationEx (which is a great
asset though) is not an option :-)

What I want to do is capture the WM_PASTE message to prevent pasting to the
textbox, any suggestions on how this could be done without overriding
WndProc?

regards,

Peter
 
Your code is not an application? Are you building a library for other
applications to use?

Paul T.
 
I am creating a custom TextBox Control, so yes I am making a library of
custom controls for our company :-)

So I want to handle the paste functionality within the TextBox control to
prevent it from happening. Is this possible without WndProc?

/ Peter
 
I don't see any way to do it without subclassing the control, no.

Paul T.
 
Paul,

I am not sure I understand you correct here, I am subclassing the TextBox
class into my own TextBoxInt class. I am overriding the KeyPress method to
make sure only valid characters are entered. However, the user can still
copy/paste illegal characters into the TextBoxInt, which is why I need to
prevent that functionality (or handle it in some way).

But as WndProc isn't available it seems hard to intercept any pasting into
the custom TextBoxInt control. A workaround, which is very ugly, is to
override the TextChange event and validate the text when it changes. In this
way it is possible to catch a paste and if the new text is invalid, fix the
text back to the previous state (which was valid).

thanks,

Peter
 
Yep. and unfortunately I don't think there's much option other than your
workaround. Without function pointer support, you're kinda stuck.

-Chris


PeterB said:
Paul,

I am not sure I understand you correct here, I am subclassing the TextBox
class into my own TextBoxInt class. I am overriding the KeyPress method to
make sure only valid characters are entered. However, the user can still
copy/paste illegal characters into the TextBoxInt, which is why I need to
prevent that functionality (or handle it in some way).

But as WndProc isn't available it seems hard to intercept any pasting into
the custom TextBoxInt control. A workaround, which is very ugly, is to
override the TextChange event and validate the text when it changes. In this
way it is possible to catch a paste and if the new text is invalid, fix the
text back to the previous state (which was valid).

thanks,

Peter


Paul G. Tobey said:
I don't see any way to do it without subclassing the control, no.

Paul T.

PeterB said:
I am creating a custom TextBox Control, so yes I am making a library of
custom controls for our company :-)

So I want to handle the paste functionality within the TextBox control to
prevent it from happening. Is this possible without WndProc?

/ Peter

"Paul G. Tobey [eMVP]" <ptobey no spam AT no instrument no spam DOT com>
skrev i meddelandet Your code is not an application? Are you building a library for other
applications to use?

Paul T.

Well... it's not an application, so using ApplicationEx (which is a
great
asset though) is not an option :-)

What I want to do is capture the WM_PASTE message to prevent
pasting
 
Ok, thanks for the help guys!

Would it be possible to make the textchange event occur before the actual
re-painting of the textbox. What I want to achieve is to remove the
flashing, non-wanted characters from the paste.

Also, sometimes I add special characters (for example hyphen/minus sign to
make the number in the textbox negative), the cursor is then moved to one
position and then back to the original position. Would it be possible to
prevent this flashing as well?

/ Peter


Chris Tacke said:
Yep. and unfortunately I don't think there's much option other than your
workaround. Without function pointer support, you're kinda stuck.

-Chris


PeterB said:
Paul,

I am not sure I understand you correct here, I am subclassing the TextBox
class into my own TextBoxInt class. I am overriding the KeyPress method to
make sure only valid characters are entered. However, the user can still
copy/paste illegal characters into the TextBoxInt, which is why I need to
prevent that functionality (or handle it in some way).

But as WndProc isn't available it seems hard to intercept any pasting into
the custom TextBoxInt control. A workaround, which is very ugly, is to
override the TextChange event and validate the text when it changes. In this
way it is possible to catch a paste and if the new text is invalid, fix the
text back to the previous state (which was valid).

thanks,

Peter


Paul G. Tobey said:
I don't see any way to do it without subclassing the control, no.

Paul T.

I am creating a custom TextBox Control, so yes I am making a library of
custom controls for our company :-)

So I want to handle the paste functionality within the TextBox
control
to
prevent it from happening. Is this possible without WndProc?

/ Peter

"Paul G. Tobey [eMVP]" <ptobey no spam AT no instrument no spam DOT com>
skrev i meddelandet Your code is not an application? Are you building a library for other
applications to use?

Paul T.

Well... it's not an application, so using ApplicationEx (which is a
great
asset though) is not an option :-)

What I want to do is capture the WM_PASTE message to prevent
pasting
to
the
textbox, any suggestions on how this could be done without overriding
WndProc?

regards,

Peter


"Peter Foot [MVP]" <[email protected]> skrev i meddelandet
You cannot override the WndProc in the Compact Framework. You
can
use
the
Smart Device Framework ApplicationEx object to implement an
IMessageFilter
to capture incoming windows messages for your application.
www.opennetcf.org/sdf/

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Do have an opinion on the effectiveness of Microsoft Windows Mobile
and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups

Hi!

I'm trying to override WndProc( ref Message m) in my custom TextBox
control.
Unfortunately it seems like the System.Windows.Forms.Message class
is
not
available in CF. Is there a was to reference this class anyway?

I tried referencing Microsoft.WindowsCE.Forms but I get the
following
compile error:
WndProc(ref Microsoft.WindowsCE.Forms.Message)': no suitable method
found
to
override

I am not sure whether it is impossible to override the WndProc
method
in
this context or if I'm just using the wrong Message definition.

Ideas?

Thanks!

/ Peter
 
Override OnPaint and use a synchronization object like a Monitor wait or
some such to serialize the repaint after you handle the textchange.

-Chris


PeterB said:
Ok, thanks for the help guys!

Would it be possible to make the textchange event occur before the actual
re-painting of the textbox. What I want to achieve is to remove the
flashing, non-wanted characters from the paste.

Also, sometimes I add special characters (for example hyphen/minus sign to
make the number in the textbox negative), the cursor is then moved to one
position and then back to the original position. Would it be possible to
prevent this flashing as well?

/ Peter


Chris Tacke said:
Yep. and unfortunately I don't think there's much option other than your
workaround. Without function pointer support, you're kinda stuck.

-Chris
method
to
make sure only valid characters are entered. However, the user can still
copy/paste illegal characters into the TextBoxInt, which is why I need to
prevent that functionality (or handle it in some way).

But as WndProc isn't available it seems hard to intercept any pasting into
the custom TextBoxInt control. A workaround, which is very ugly, is to
override the TextChange event and validate the text when it changes.
In
this
way it is possible to catch a paste and if the new text is invalid,
fix
the
text back to the previous state (which was valid).

thanks,

Peter


"Paul G. Tobey [eMVP]" <ptobey no spam AT no instrument no spam DOT com>
skrev i meddelandet I don't see any way to do it without subclassing the control, no.

Paul T.

I am creating a custom TextBox Control, so yes I am making a
library
of
custom controls for our company :-)

So I want to handle the paste functionality within the TextBox control
to
prevent it from happening. Is this possible without WndProc?

/ Peter

"Paul G. Tobey [eMVP]" <ptobey no spam AT no instrument no spam
DOT
com>
skrev i meddelandet Your code is not an application? Are you building a library for other
applications to use?

Paul T.

Well... it's not an application, so using ApplicationEx (which
is
 
Thanks for the idea Chris, however, it seems like you can't override OnPaint
for a custom control inherited from TextBox :-(

If I look at your TextBoxEx, it does inherit from TextBox and override
OnPaint but for design support (or do I misunderstand the code?). Anyway, I
can't get OnPaint to fire in my own code.

I guess I could inherit from Control class instead but I get the impression
this would demand a lot of extra work. I'm having a look at that right now..

/ Peter
 
You're probably right. There are definitely a few things with Controls I'd
change if I had my way.

-Chris
 
Back
Top