dotnet-Snippets.com
Snippets: 75 | Registered User: 84 | Visitors online: 2
Main Menu

Home
Random Snippet
FAQs
Contact Us
Imprint
RSS Feeds

Rss All languages
Rss C#
Rss VB.NET
Rss C++
Rss J#
Rss ASP.NET
Jobs

dotnet Jobs
Google Ads

Sri Lanka .NET 
                Forum Member
Apend Text to a Richtextbox

Author: Guest
Programming Language: VB.NET Rating:
not yet rated

Views: 1736

Description:

5 times overloded Method to add a String to a Richtext box.

Syntax:
AppendText(Text,[Fcolor],[Bcolor],[bold])

Text = Text to add as String
Fcolor = Forground Color As System.Color
Bcolor = Background Color as System.Color
bold = set to boolean true for a bold font style




Visual Basic
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

    ''' <summary>
    ''' Add a String to a RichTextbox
    ''' </summary>
    ''' <param name="Text"></param>
    ''' <remarks>AppendText(Text,[Fcolor],[Bcolor],[bold])  </remarks>
    Overloads Sub AddText(ByVal Text As String)
        AppendText(Text, Color.Black, Color.White, False)
    End Sub
    ''' <summary>
    ''' Add a String to a RichTextbox
    ''' </summary>
    ''' <param name="Text"></param>
    ''' <param name="BoolBold">set to true for bold font style</param>
    ''' <remarks>AppendText(Text,[Fcolor],[Bcolor],[bold] ) </remarks>
    Overloads Sub AddText(ByVal Text As String, ByVal BoolBold As Boolean)
        AppendText(Text, Color.Black, Color.White, BoolBold)
    End Sub
    ''' <summary>
    ''' Add a String to a RichTextbox
    ''' </summary>
    ''' <param name="Text"></param>
    ''' <param name="ForegroundColor">define a fore ground color</param>
    ''' <remarks>AppendText(Text,[Fcolor],[Bcolor],[bold])  </remarks>
    Overloads Sub AddText(ByVal Text As String, ByVal ForegroundColor As Color)
        AppendText(Text, ForegroundColor, Color.White, False)
    End Sub
    ''' <summary>
    ''' Add a String to a RichTextbox
    ''' </summary>
    ''' <param name="Text"></param>
    ''' <param name="ForegroundColor">define a fore ground color</param>
    ''' <param name="BoolBold">set to true for bold font style</param>
    ''' <remarks>AppendText(Text,[Fcolor],[Bcolor],[bold])  </remarks>
    Overloads Sub AddText(ByVal Text As String, ByVal ForegroundColor As Color, ByVal BoolBold As Boolean)
        AppendText(Text, ForegroundColor, Color.White, BoolBold)
    End Sub
    ''' <summary>
    ''' Add a String to a RichTextbox
    ''' </summary>
    ''' <param name="Text"></param>
    ''' <param name="ForegroundColor">define a fore ground color</param>
    ''' <param name="BackgroundColor">define a back ground color</param>
    ''' <remarks>AppendText(Text,[Fcolor],[Bcolor],[bold])  </remarks>
    Overloads Sub AddText(ByVal Text As String, ByVal ForegroundColor As Color, ByVal BackgroundColor As Color)
        AppendText(Text, ForegroundColor, BackgroundColor, False)
    End Sub
    ''' <summary>
    ''' Add a String to a RichTextbox
    ''' </summary>
    ''' <param name="Text"></param>
    ''' <param name="ForegroundColor">define a fore ground color</param>
    ''' <param name="BackgroundColor">define a back ground color</param>
    ''' <param name="BoolBold">set to true for bold font style</param>
    ''' <remarks>AppendText(Text,[Fcolor],[Bcolor],[bold])  </remarks>
    Overloads Sub AddText(ByVal Text As String, ByVal ForegroundColor As Color, ByVal BackgroundColor As Color, ByVal BoolBold As Boolean)
        AppendText(Text, ForegroundColor, BackgroundColor, BoolBold)
    End Sub
    Private Sub AppendText(ByVal text As String, ByVal ForegroundColor As Color, ByVal BackgroundColor As Color, ByVal BoolBold As Boolean)
        'text = text & vbNewLine
        Dim start As Integer = RichTextBox1.TextLength
        RichTextBox1.AppendText(text)
        Dim [end] As Integer = RichTextBox1.TextLength
        RichTextBox1.[Select](start, [end] - start)
        If True Then
            If BoolBold Then
                RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Bold)
            Else
                RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Regular)
            End If

            RichTextBox1.SelectionColor = ForegroundColor
            RichTextBox1.SelectionBackColor = BackgroundColor
        End If
        RichTextBox1.SelectionLength = 0
        RichTextBox1.ScrollToCaret()
        RichTextBox1.Refresh()
    End Sub

This Snippets could be interesting for you:
No results available

Poor Excellent
1 2 3 4 5 6 7 8 9 10
Sign in to vote for this snippet.

Comments:
(Please log in to write an comment.)