Object reference not set to an instance of an object.

G

Guest

I’m writing a Windows application with VB.NET. The application I’m creating
using a user control which I have written. The user control has some buttons,
Panels, Combobox and a Rich textbox. The user control would like to edit some
text in the textbox but getting problem. (My Rich textbox is called rtManus).
My problem code is:

If Not rtManus.SelectionFont Is Nothing Then
Dim currentFont As System.Drawing.Font = rtManus.SelectionFont
Dim newFontStyle As System.Drawing.FontStyle
If rtManus.SelectionFont.Bold = False Then
newFontStyle = FontStyle.Bold
End If
rtManus.SelectionFont = New Font(currentFont.FontFamily, _
currentFont.Size, newFontStyle)
End If

Error message is: Object reference not set to an instance of an object.

The code is working well two times, but the third time it crash. This code
has been copied from .NET help. Can anyone tell me what the problem is, pleas?
 
G

Guest

When the code is written as below it doesn’t crash but it doesn’t work
properly either... Just notice when I select text by double-clicking on text
then this code working (not selecting text by mouse button pressed and moved
over text).

Christer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top