473,396 Members | 1,891 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,396 software developers and data experts.

Is this a bug of RichTextBox control??

Hi all

I are stuck on a problem with RichTextBox control. On a simple form - a
label, a richtext control, a button, in the button even method I write:

private void button1_Click(object sender, System.EventArgs e)
{
try
{
string name = this.richTextBox1.SelectionFont.FontFamily.Name;
this.label1.Text = name;
}
catch (Exception ex)
{
Debug.WriteLine (ex.ToString());
}
}

I just simply want to get the font of the text in the rich text box.

I created a short text in Microsoft Word 2000, saved as Rich Text Format,
then I pasted the text into the Rich Text box on the form. When I high-light
the text in the box
and clicked the button, the program throws a exception:
"System.NullReferenceException: Object reference not set to an instance of
an object".

If I create the text in a pain text editor and paste it into the rich text
box, there is no problem.

Is it because Word contains special characters that are not recognised by
the rich text control? But the text created with Word is in RTF format.
I don't know why there is a problem.

Anyone have notice this problem, or know why?

Many thanks
Yuelin
Nov 15 '05 #1
1 3592
Yuelin <li***@lineone.net> wrote:

<snip>
string name = this.richTextBox1.SelectionFont.FontFamily.Name;
<snip>
and clicked the button, the program throws a exception:
"System.NullReferenceException: Object reference not set to an instance of
an object".
Anyone have notice this problem, or know why?


<snip>

Well the first thing to do is find out what exactly is causing a
NullReferenceException - it could be quite a few things in the above,
given the number of levels of indirection. Break the above up into
separate lines, and work out which of the bits ends up being null, thus
causing the exception. My guess is that it's SelectionFont that returns
null, as it says in the documentation:

<quote>
If the current text selection has more than one font specified, this
property is a null reference (Nothing in Visual Basic).
</quote>

So if (possibly invisibly) you'd got more than one font in the
selection, that would definitely explain it, and it wouldn't be a bug
at all.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #2

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

Similar topics

1
by: vanvee | last post by:
Hi I have a user control that contains a RichTextBox in vb.net. In my program, I create multiple instances of this control (with the RichTextBox being in each one), that appear one above the...
1
by: Nathan Carroll | last post by:
In an mdi environment I constructed a child for with a richtextbox control that is used to load .rtf's. This works fine on the intiatial load of the form but when for is closed and reopened later...
10
by: D Steward | last post by:
I can't seem to add a newline (/n) to get a richtextbox control to display text on successive lines. The text that I type is overwritten. How do I remedy this My example richTextBox->Multiline...
2
by: Neo Chou | last post by:
Greetings! I'm trying to make my ASPX page able to process WORD format document. I learned that RichTextBox might help me, but I can't use it either by adding it to my Web Control list or by...
1
by: Eric | last post by:
Using the 1.1 framework. We are using a newly created instance of a RichTextBox Class in our server code to manipulate RTF that is stored in the database. To clarify, we are not using or...
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...
2
by: AWesner | last post by:
I am currently working to create a VB program that will do more detailed in-file text search functions than windows has to offer. I have a form with a RichTextBox control to display the text that...
9
by: James Wong | last post by:
Hi, I use the RichTextBox in my program. It will use different language in this RichTextBox (chinese and english characters), and it set the "DualFont" and use different fonts. By the way, how...
3
by: michael sorens | last post by:
The documentation for the RichTextBox is sketchy at best. I want to do a very simple task but I cannot find information on this. I am using a RichTextBox as an output window. Some text I want to...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.