Convert Type Richtextbox to Textbox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to convert a richt text box to a textbox? My code lloks like this

Dim txtBox as System.Windows.Forms.TextBo
dim richTxtBox as System.Windows.Forms.RichTextBo

txtBox=ctype(richTxtBox,System.Windows.Forms.TextBox

I get an error message: An unhandled expression of type System.InvalidCastException
Additional Information: Specified cast is not vali

I know this tells me that i can't convert it to a textbox but is there a workaround for this one

Thanks :)
 
Ed said:
Is there a way to convert a richt text box to a textbox? My code
lloks like this:

Dim txtBox as System.Windows.Forms.TextBox
dim richTxtBox as System.Windows.Forms.RichTextBox

txtBox=ctype(richTxtBox,System.Windows.Forms.TextBox)

I get an error message: An unhandled expression of type
System.InvalidCastException. Additional Information: Specified cast
is not valid

I know this tells me that i can't convert it to a textbox but is
there a workaround for this one?

No, Richtextbox is not derived from Textbox, but both are derived from
Textboxbase.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
* "=?Utf-8?B?RWQ=?= said:
Is there a way to convert a richt text box to a textbox? My code lloks like this:

Dim txtBox as System.Windows.Forms.TextBox
dim richTxtBox as System.Windows.Forms.RichTextBox

txtBox=ctype(richTxtBox,System.Windows.Forms.TextBox)

I get an error message: An unhandled expression of type System.InvalidCastException.
Additional Information: Specified cast is not valid

RichTextBox and TextBox have the same base class, but RichTextBox
doesn't inherit from TextBox, so this won't work.
 
So you are saying that there really is now way for me to implement this? If yes, then how can I make a paramter accept both richtextbox and textbox controls? currently My parameter is (ByVal txtBox as system.windows.form.textbox).
 
Ed said:
So you are saying that there really is now way for me to implement
this? If yes, then how can I make a paramter accept both richtextbox
and textbox controls? currently My parameter is (ByVal txtBox as
system.windows.form.textbox).

As I said, both are derived from Textboxbase, so you can declare it As
system.windows.form.textboxbase. You'll be able to pass both types of
textboxes.

Of course, you can only access the members of the Textboxbase class, not
those that are only there for the derived classes. If you also want to
access the specific ones, you must overload the procedure (same name, but
the one takes a richttextbox and the other a textbox).


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Back
Top