473,658 Members | 2,628 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(o bject sender, System.EventArg s e)
{
try
{
string name = this.richTextBo x1.SelectionFon t.FontFamily.Na me;
this.label1.Tex t = 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.NullRef erenceException : 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 3629
Yuelin <li***@lineone. net> wrote:

<snip>
string name = this.richTextBo x1.SelectionFon t.FontFamily.Na me;
<snip>
and clicked the button, the program throws a exception:
"System.NullRef erenceException : 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
NullReferenceEx ception - 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.co m>
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
2573
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 other on a panel. The problem is that each control may have varying amounts of data, and so each RichTextBox (within each control) needs to size to fit the amount of text within that RichTextBox. I've tried multiplying the size of a single line...
1
2487
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 I get: System.ObjectDisposedException: Cannot access a disposed object named "RichTextBox". Object name: "RichTextBox". at System.Windows.Forms.Control.CreateHandle() at System.Windows.Forms.TextBoxBase.CreateHandle() at...
10
11630
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 = true richTextBox->Text = S"First line /n" richTextBox->Text = S"Second line" Thanks
2
30520
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 writing "<asp:RichTextBox id="c1" />" in the ASPX file. The error message shows "Cannot find RichTextBox in the namespace of web controls" (something like that). Is there any way to add RichTextBox in ASPX file? Or where can I find a substitute?...
1
2679
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 attempting to use this class in the aspx page that calls the code, nor is the 'using System.Windows.Forms' referenced in any of the aspx pages. The first client using this software has been experiencing an error that we cannot reproduce in-house. The...
1
1679
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 value from combo box after entering of all the details i'll click on one of the command buttons then it will save the contents of the controls which i placed on the richtextbox into a file then i'll click on another command button so it will...
2
2882
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 has been found in the files. The problem is that when a search has been found that is at the very start of the file and the .select method is used to select just the first portion it ends up selecting everything in the RichTextBox control...
9
4861
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 can I print out this content to printer easily? Thanks! James
3
7172
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 just add plain (e.g.. rtf.Text += "new stuff..."; ) but some text, when added, I want to be in a different color or font size. Find() will not work because the text will vary. I have delimiters on it so I could recognize it with a regular ...
4
13438
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 oldest characters it contains start rolling off the top into the bit bucket, does it simply start silently ignoring appends until some characters, are deleted, or does some kind of exception get thrown? I've heard numerous opinions on what the...
0
8330
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8850
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8523
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8626
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5649
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2749
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 we have to send another system
2
1975
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.