Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi there!

 

I'm trying to write a kind of simple textwriter in VB.NET

In visual basic 6, this whas quite easy!

But in VB.NET i noticed that the bold property of the selectionfont is readony...

 

I know I can set the font like this:

 

Dim Myfont As New Font("Tahoma", FontStyle.Bold)

 

But in this case, if the font was underlined as well, the underline is gone! :(

 

So I have to check, all the applied font-styles, before i could set the font! :confused:

 

I wrote some code, which processed 1 character at a time.

That works, but very, very slow!

 

Does anyone knows some code, to help me out???

 

Thanks!

 

Greets,

 

Erik van der Velden.

Holland

  • Leaders
Posted

       With rtfChannel
           .SelectionStart = Len(.Text)
           .SelectionColor = System.Drawing.Color.SteelBlue
           .SelectedText = inData
       End With

the colour bit being this ...

rtfChannel.SelectionColor = System.Drawing.Color.SteelBlue

rtfChannel being the richtextbox.:)

 

oops and the Font ?

rtfChannel.SelectionFont = New System.Drawing.Font("Tahoma", 10.0!)

  • Leaders
Posted

almost forgot the Bold bit.

rtfChannel.SelectionFont = New System.Drawing.Font(read_font, 10.0!, FontStyle.Bold)
'// read_font is where your font would be btw.

hope this helps , the richtextbox control is quite good in .net once you get used to it :)

Posted

Thank you very much for you reply's!

 

But I'm still having problems!

 

When the selectedtext in the richtextbox contains multiple fonts (or fontstyles (size, bold, undelined, italic or whatever...)) the Selectionfont property returns 'Nothing'. So I have to read until something in the font changes (that's a lot to check!) and then set the text to far, etcetera....

This works, but very slow! Especialy when you select multiple lines with different fonts or fontstyles!

I'm thinking about sending windows messages to the richtextbox.

Does anyone has expierence?

 

Hoping to hear from you!

 

Greets,

 

Erik van der Velden.

  • Leaders
Posted

are you receiving the multiple fonts / colours in to the richtextbox from another source ( like with irc , where you have to sort the correct colours for the different chars )?

goede middag:)

Posted

Goede middag! Very good!

 

I'm not sure I understand what you mean.

I am reading a RTF file from disk.

My problem is (for example...) that when I have a word which contains 2 different fonts, the first 3 chars are bold, and the second 3 are underlined.

Now I select the complete word en want to make the complete word Italic AS WELL (without loosing the fontstyle per char!)

But now I have to fontstyle for the complete word!

In VB6 you should say: MyRtfBox.SelectionItalic = True

This will make the word Italic as well, but also it's current state! (Bold or Undelined and different font!)

How should I do this with the richtextbox in VB.NET?

 

Thanks again!

 

Goede middag!

  • Leaders
Posted

if you are reading RTF from a disk , why not use richtextbox.SelectedRtf ? because if it's rtf in the first place you shouldnt need to decode for the different fonts / colours :-\

eg:

rtb.SelectedRtf = "myrtf file"

thats if it's actually rtf format you are reading :)

Posted

Once i have read the Rtf from the file... THEN i want to change the fontstyle of some words.

Divil, thanks for the link to the article.

I will try it tomorrow.

As you can read in my first message, i already tried this myself.

It worked, but very slow. Perhaps is this code better!

 

Thanks a lot all of you!

 

Erik.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...