473,385 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Convert Type Richtextbox to Textbox

Ed
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.TextB ox

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 :)
Nov 20 '05 #1
4 3044
"Ed" <an*******@discussions.microsoft.com> 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.TextB ox)

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

Nov 20 '05 #2
* "=?Utf-8?B?RWQ=?=" <an*******@discussions.microsoft.com> 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.TextB ox)

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/>
Nov 20 '05 #3
Ed
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).
Nov 20 '05 #4
"Ed" <an*******@discussions.microsoft.com> 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

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: s-galit | last post by:
how to convert TextBox to RichTextBox? thanks in advanced
1
by: Sam | last post by:
I need some help...pleas Can someone tell me how, using the richtextbox's Lines\StringArray property, I can add text, line after individual line, at run time, to a richtextbox I have search all of...
1
by: tulasi | last post by:
I am placing textbox controls and combo box controls on richtext box and 2 command buttons on form control. after executing the application i'll place some text into textbox controls and select a...
0
by: AxOn | last post by:
Hi! I'm having trouble creating a save funktion. How can I save the contens of a new richTextBox that is created from an "external" class file? The open funktion looks like this: public void...
1
by: Mathias Weyel | last post by:
Hi Group! I have a simple GUI featuring a RichTextBox and a Button. On Button click, I start a BackgroundWorker that performs a query on the database firing a ProgressChangedEvent for every row....
0
by: Tom | last post by:
When I use ctrl-c to copy and ctrl-v to paste from a RichTextBox into NotePad ... I get nice ASCII text with the proper returns. Everything looks good. When I paste into WordPad ... I get the...
4
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I have a multiline RichTextBox that I use for data logging. I'm concerned about how the AppendText method reacts when over time the maximum number of characters have been added. Do the...
0
by: randadotexas | last post by:
Hello, everybody. I have a form with a RichTextBox or a simple TextBox control. It contains hundreds of text lines, so control has to be scrolled. I want to send to a printer only the lines...
1
by: randadotexas | last post by:
Hello, everybody. I'm working on a Vb.net project. I have a form with a RichTextBox or a simple TextBox control. It contains hundreds of text lines, so the control has to be scrolled. I want...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.