-
July 19th, 2002, 02:09 PM
#1
Bolding text
I want to bold text, I can do it with a button easily, but i need for it to do it automatically.
For example I need
txtquote1.Text = txtquote1.Text & vbNewLine & "Lettershop" & vbNewLine
"Lettershop" to be bold
How do i put that in code?
-
July 19th, 2002, 02:40 PM
#2
Textboxes can only display one font at at time. You need to use a richtextbox to display multiple fonts, then use SelText properties to change the text characteristics.
-
July 19th, 2002, 02:41 PM
#3
yeah, I am using a richtextbox, but the txtquote1.selbold=true does nothing
-
July 19th, 2002, 02:52 PM
#4
Private Sub Command1_Click()
'make fox bold
RichTextBox1.SelStart = RichTextBox1.Find("fox")
RichTextBox1.SelLength = 3
RichTextBox1.SelBold = True
End Sub
Private Sub Form_Load()
RichTextBox1.Text = "The quick brown fox jumped over the lazy brown dog."
End Sub
Last edited by DSJ; July 19th, 2002 at 02:56 PM.
-
July 19th, 2002, 02:54 PM
#5
Is there a way to bold text that you are outputting
lets say,
richtextbox1 = "Test line here"
But i want that whole sting bold... can i do that.
I want only that string bold, even if that same string was in the textbox 100 times.
is it possible?
-
July 19th, 2002, 02:57 PM
#6
SelBold must be used in conjunction with SelStart and SelLen methods. The example below will make the word "There" bold
Code:
Private Sub Command1_Click()
Dim x As Long
RichTextBox1.Text = "Hello" ' Print some text
RichTextBox1.Text = RichTextBox1.Text & " There" ' add some more
x = InStr(1, RichTextBox1.Text, "There") ' Locate text to colorize
RichTextBox1.SelStart = x - 1 ' set starting point
RichTextBox1.SelLength = 5 ' Set length of "There"
'RichTextBox1.SelColor = vbRed ' Colorize it
RichTextBox1.SelBold = True ' Bold it
End Sub
-
July 19th, 2002, 03:54 PM
#7
Originally posted by thecaptainjs
Is there a way to bold text that you are outputting
lets say,
richtextbox1 = "Test line here"
But i want that whole sting bold... can i do that.
I want only that string bold, even if that same string was in the textbox 100 times.
is it possible?
Code:
'The following code will change the color and boldness of the selected string while entering text in the RichBox.
Dim start As Long, BoldString As String
Private Sub Form_Load()
start = 1
BoldString = "Test line here"
End Sub
Private Sub RichTextBox1_Change()
Dim pos As Long
With RichTextBox1
pos = InStr(start, .Text, BoldString)
If pos > 0 Then
start = pos + Len(BoldString)
.SelStart = pos - 1
.SelLength = Len(BoldString)
.SelBold = True
.SelColor = vbRed
.SelStart = pos + .SelLength
.SelBold = False
.SelColor = vbBlack
End If
End With
End Sub
-
July 19th, 2002, 03:56 PM
#8
Originally posted by thecaptainjs
Is there a way to bold text that you are outputting
lets say,
richtextbox1 = "Test line here"
But i want that whole sting bold... can i do that.
I want only that string bold, even if that same string was in the textbox 100 times.
is it possible?
Code:
'The following code find all occurrences of a string in a RichBox and make them Bold with a Blue color.
Private Sub Command1_Click()
Dim BoldString As String, pos As Long
BoldString = "Test line here"
With RichTextBox1
pos = InStr(1, .Text, BoldString)
Do While pos > 0
.SelStart = pos - 1
.SelLength = Len(BoldString)
.SelBold = True
.SelColor = vbBlue
pos = InStr(pos + Len(BoldString), .Text, BoldString)
Loop
End With
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|