473,505 Members | 13,982 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3610
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
2568
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
2469
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
11604
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
30515
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
2668
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
1659
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
2861
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
4838
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
7154
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
13400
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
7216
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
7098
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
7303
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,...
0
7367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7018
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
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.