.a bit.confusing, though somewhat I have an idea.
To clear this up for me and possibly others, do you want to type in rtb(RichTextBox) and Then change font after?.orElse do you want to always have line.1 w/(any font, size 72, bold) and line.2 w/(any font, size 48, Italic)? orElse btn.Click to change font for those 2lines only?
codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
See if this helps.
Public Class Form1
Private xnL As String = vbNewLine
Private myCoolFont1 As New Font("verdana", 23, FontStyle.Bold), myCoolFont2 As New Font("georgia", 33, FontStyle.Italic)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With RichTextBox1 : .Text &= "line 1" & xnL & "line 2" & xnL & "line 3" : .HideSelection = False : End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
With RichTextBox1 : setFont(RichTextBox1, 0, myCoolFont1) : setFont(RichTextBox1, 1, myCoolFont2) : End With
End Sub
Private Sub setFont(ByVal selRtb As RichTextBox, ByVal selLine As Integer, ByVal selFont As Font)
With selRtb
If .Lines.Length >= selLine Then : Dim iStartIndex As Integer = 0
For i As Integer = 0 To selLine - 1 : iStartIndex += .Lines(i).Length + 1 : Next
.Select(iStartIndex, .Lines(selLine).Length) : .SelectionFont = selFont
End If
End With
End Sub
End Class
p.s.am a lil' too busy to add a few comments, though this helped to possibly help you. http://www.vbforums.com/showpost.php?p=3355847&postcount=3
codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
.a bit.confusing, though, see if this helps?.
Public Class Form1
Private myCoolFont1 As New Font("verdana", 23, FontStyle.Bold), myCoolFont2 As New Font("georgia", 33, FontStyle.Italic)
Private isFont1 As Boolean = False '// Toggles Font.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
With RichTextBox1
If isFont1 Then
.SelectionFont = myCoolFont2
isFont1 = False
ElseIf Not isFont1 Then
.SelectionFont = myCoolFont1
isFont1 = True
End If
End With
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
With RichTextBox1 : .HideSelection = False : End With
End Sub
End Class
codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384