|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
appending colored / fonted <?> text to a richtextboxSorry, it's getting late and I'm tired.
I'm trying to fill a richtect box with text derived from the array I was asking about earlier (thank you). I'm not sure what I'm seeing - since most of the examples show how to load and save an rtf file into / from a rtbox (may want to save this guy, so that'll come in handy, later). Does anyone one know of a sample showing how to append, piecemeal, text into an rtb with format changes as needed?? ((And if you do, would you point me to it - I told you I'm getting tired :) )) Going back to my example of MP3's, say I want the Artist in 14 pt, blue; on a new line the album in 12 point, red and the songs of the album, each on a seperate line in 12 pt black. Pointers, please //al al jones <alfredmjo***@shotmail.com> wrote in
Show quoteHide quote news:1dxrhc232u8x5$.w458hgao9lhz.dlg@40tude.net: W00t, a question I can (sort of) answer.> > Sorry, it's getting late and I'm tired. > > I'm trying to fill a richtect box with text derived from the array > I was asking about earlier (thank you). I'm not sure what I'm > seeing - since most of the examples show how to load and save an > rtf file into / from a rtbox (may want to save this guy, so > that'll come in handy, later). > > Does anyone one know of a sample showing how to append, piecemeal, > text into an rtb with format changes as needed?? ((And if you do, > would you point me to it - I told you I'm getting tired :) )) > > Going back to my example of MP3's, say I want the Artist in 14 pt, > blue; on a new line the album in 12 point, red and the songs of > the album, each on a seperate line in 12 pt black. Pointers, > please //al I've split the rtf into 5 sections, style header, colour header, initialisation (other bits), main text, end. I don't think carriage returns in the file make any difference to how it's presented, so you might as well build up each line and writeline to the file. For the style header, replace with whatever fits. Here's an example. I'm not quite sure how each font is described, so you'll have to do some experimenting yourself. STYLE HEADER {\rtf1\ansi\ansicpg1252\deff0\deflang1033\deflangfe1028{\fonttbl{\f0 \fmodern\fprq1\fcharset0 Courier New;}} For the Colour header, replace with whatever fits. Note that colours are referred to by the place in this section, so colour 1 is red255 \green0\blue0 and so on. COLOUR HEADER {\colortbl ;\red255\green0\blue0;\red0\green192\blue192;\red0\green255 \blue255;} I don't know what all this means, but copying it en bloc seems to work. INITIALISATION (OTHER BITS) \viewkind4\uc1\pard\cbpat3\nowidctlpar\f0\fs20 For the main block of text, write whatever you want, but note that \par means new line. Also note that \highlightn<space> changes background colour to colour n (see colour header above), which will remain so until you switch to another colour. Note that colour 0 will switch highlighting off. Remember the space after n. If you want to change the foreground colour, use cf instead of highlight. MAIN TEXT Rich \highlight1 text\highlight2 files suck\par Badly and\highlight0 utterly The end bit is just a curly bracket. END } Copy the examples line by line into a textfile, rename it as *.rtf, then play around with it to see how it works. Does this means I'm an accepted member of the VB community now I've answered a question? -- Cheers, ymt. "al jones" <alfredmjo***@shotmail.com> schrieb: Mark the text using the control's 'Select' method and set the control's > I'm trying to fill a richtect box with text derived from the array I was > asking about earlier (thank you). I'm not sure what I'm seeing - since > most of the examples show how to load and save an rtf file into / from a > rtbox (may want to save this guy, so that'll come in handy, later). > > Does anyone one know of a sample showing how to append, piecemeal, text > into an rtb with format changes as needed?? ((And if you do, would you > point me to it - I told you I'm getting tired :) )) 'SelectionFont', 'SelectionColor', etc. properties accordingly. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> On Sun, 9 Apr 2006 12:43:10 +0200, Herfried K. Wagner [MVP] wrote:
> "al jones" <alfredmjo***@shotmail.com> schrieb: I've been to bed and still don't see that. I'm programatically creating a>> I'm trying to fill a richtect box with text derived from the array I was >> asking about earlier (thank you). I'm not sure what I'm seeing - since >> most of the examples show how to load and save an rtf file into / from a >> rtbox (may want to save this guy, so that'll come in handy, later). >> >> Does anyone one know of a sample showing how to append, piecemeal, text >> into an rtb with format changes as needed?? ((And if you do, would you >> point me to it - I told you I'm getting tired :) )) > > Mark the text using the control's 'Select' method and set the control's > 'SelectionFont', 'SelectionColor', etc. properties accordingly. line of text - how do I programatically 'select' the line which hasn't been 'printed' yet??. I'v been through the docs, seen the items you reference, but don't see how to implement them. Thanks //al Hi Al,
I haven't tried this, but I think one way to do it might be to : 1. First extract each piece of information (Artist, Album, Song...) from your array. 2. To each piece, attach RTF codes as Yuk Tang suggested. You might have to do a bit of research on this. BTW, if you find a good website, that demystifies all those RTF codes, please let me know as well. 3. Make sure that no text is selected in the RTB, and then assign the constructed RTF coded piece to the SelectedRtf property of your RTB. This will append the text to the RTB with specified colors and fonts. Do this in a loop till all your items have been covered. Yuk Tang wrote : >> Does this means I'm an accepted member of the VB community now I've Lolz ! Don't worry, you can exclusively *ask* questions all the time,>> answered a question? and still be an accepted member of the community. ;-) Regards, Cerebrus. "Cerebrus" <zorg***@sify.com> schrieb: Rich Text Format (RTF) Specification, version 1.6> 2. To each piece, attach RTF codes as Yuk Tang suggested. You might > have to do a bit of research on this. BTW, if you find a good website, > that demystifies all those RTF codes, please let me know as well. <URL:http://msdn.microsoft.com/library/en-us/dnrtfspec/html/rtfspec.asp> For simple coloring I would stick with 'Select'/'SelectionColor' instead of adding RTF code directly. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> >> Rich Text Format (RTF) Specification, version 1.6 ... URL... Thank you, Herfried. I've saved that in my "Favourites", and will studyit. I suggested adding RTF coded text directly, since it might be complicated to append a word to the RTB, then Select that word, and then change it's font and color properties. Also, it might induce some sort of flickering or the change might be noticeable to the user. I haven't tried this, so I'm just guessing. Or is there a way to set it's properties before the appended text is displayed in the control ? Thanks in advance, Regards, Cerebrus. "Cerebrus" <zorg***@sify.com> schrieb: You could either fill the control when it's not yet visible or prevent it > I suggested adding RTF coded text directly, since it might be > complicated to append a word to the RTB, then Select that word, and > then change it's font and color properties. Also, it might induce some > sort of flickering or the change might be noticeable to the user. I > haven't tried this, so I'm just guessing. from redrawing: Preventing controls from redrawing <URL:http://dotnet.mvps.org/dotnet/faqs/?id=disableredrawing&lang=en> -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> "al jones" <alfredmjo***@shotmail.com> wrote in message A crude example:-news:1d6rzlvpyeogg.6cq2hfigbiez.dlg@40tude.net... > I've been to bed and still don't see that. I'm programatically creating a > line of text - how do I programatically 'select' the line which hasn't > been > 'printed' yet??. I'v been through the docs, seen the items you reference, > but don't see how to implement them. Thanks //al Dim I As Integer, J As Integer, K As Integer Dim S As String, T As String, U As String With RichTextBox1 ..Text = "This is some text " ..SelectAll() ..SelectionFont = New Font("Tahoma", 12, FontStyle.Bold) ..SelectionColor = Color.Chartreuse I = .SelectionLength S = "This is more text" J = Len(S) ..Text &= S ..Select(I, J) ..SelectionFont = New Font("Arial", 8, FontStyle.Italic) ..SelectionColor = Color.Blue ..Select(0, 0) End With On Tue, 11 Apr 2006 04:37:24 GMT, Homer J Simpson wrote:
Show quoteHide quote > "al jones" <alfredmjo***@shotmail.com> wrote in message Aye, you've done one way what I've done another way. I don't know how many> news:1d6rzlvpyeogg.6cq2hfigbiez.dlg@40tude.net... > >> I've been to bed and still don't see that. I'm programatically creating a >> line of text - how do I programatically 'select' the line which hasn't >> been >> 'printed' yet??. I'v been through the docs, seen the items you reference, >> but don't see how to implement them. Thanks //al > > A crude example:- > > Dim I As Integer, J As Integer, K As Integer > Dim S As String, T As String, U As String > With RichTextBox1 > .Text = "This is some text " > .SelectAll() > .SelectionFont = New Font("Tahoma", 12, FontStyle.Bold) > .SelectionColor = Color.Chartreuse > I = .SelectionLength > S = "This is more text" > J = Len(S) > .Text &= S > .Select(I, J) > .SelectionFont = New Font("Arial", 8, FontStyle.Italic) > .SelectionColor = Color.Blue > .Select(0, 0) > End With times I missed the line that says that if you change the color / font and then add to the rtb that it will then use that font / color. So My code now looks like: > rtbList.SelectionFont = New Font(currentFont.FontFamily, currentFont.Size, FontStyle.Bold) which is stupidly simple.....> rtbList.AppendText(alWork.item1 & vbCrLf) > rtbList.SelectionFont = New Font(currentFont.FontFamily, currentFont.Size, FontStyle.Regular) Thanks to all who replied. //al
StringBuilder termination char
Run code from IDE Save graphics image to bitmap? Drawing points in degrees!!! 32bit image quality in menus and tool bar strips VB2005 - Secure Access to SQL Server through Application Only How can I know my application's path? decimal serious problem mousehover how to have Insert or Select Statement NOT allow Duplicates |
|||||||||||||||||||||||