PC Review


Reply
Thread Tools Rate Thread

Convert Type Richtextbox to Textbox

 
 
=?Utf-8?B?RWQ=?=
Guest
Posts: n/a
 
      13th Apr 2004
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
 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      13th Apr 2004
"Ed" <(E-Mail Removed)> schrieb
> 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



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      13th Apr 2004
* "=?Utf-8?B?RWQ=?=" <(E-Mail Removed)> scripsit:
> 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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
Reply With Quote
 
=?Utf-8?B?RWQ=?=
Guest
Posts: n/a
 
      14th Apr 2004
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).
 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      14th Apr 2004
"Ed" <(E-Mail Removed)> schrieb
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Textbox vs. RichTextbox + Linebreaks? =?Utf-8?B?QmVuIFIu?= Microsoft Dot NET 4 2nd Apr 2007 01:59 PM
TextBox/Richtextbox scroll at bottom =?Utf-8?B?QnJpYW4gS2VhdGluZw==?= Microsoft C# .NET 0 23rd Nov 2006 12:19 PM
Autosize Textbox or RichTextBox =?Utf-8?B?QnJld3NraQ==?= Microsoft Dot NET Framework Forms 3 15th Dec 2005 04:31 PM
how to convert TextBox to RichTextBox? =?Utf-8?B?cy1nYWxpdA==?= Microsoft Dot NET 2 14th Oct 2004 04:55 PM
Can you put vertical text in a textbox/richtextbox James Dean Microsoft C# .NET 1 7th Jul 2004 01:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:21 AM.