Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
what I mean by font style buttons is link bold, underline and ect.. I want buttons that you can click then like bold and underline and it show the font style as bold and underline. I try to this but it was too bugly but also I will like the buttons can be checked or unchecked.

So can you please help me this this few line of code

VB
Private Sub RichTextBox1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RichTextBox1.SelectionChanged
        If RichTextBox1.SelectionFont.Bold = True Then
            BCheckBox.Checked = True
            UCheckBox.Checked = False
            SCheckBox.Checked = False
            ICheckBox.Checked = False
        ElseIf RichTextBox1.SelectionFont.Bold & RichTextBox1.SelectionFont.Italic = True Then
            UCheckBox.Checked = False
            SCheckBox.Checked = False
            ICheckBox.Checked = True
            BCheckBox.Checked = True
        ElseIf RichTextBox1.SelectionFont.Bold & RichTextBox1.SelectionFont.Italic & RichTextBox1.SelectionFont.Underline = True Then
            UCheckBox.Checked = True
            SCheckBox.Checked = False
            ICheckBox.Checked = True
            BCheckBox.Checked = True
        ElseIf RichTextBox1.SelectionFont.Bold & RichTextBox1.SelectionFont.Italic & RichTextBox1.SelectionFont.Underline & RichTextBox1.SelectionFont.Strikeout = True Then
            UCheckBox.Checked = True
            SCheckBox.Checked = True
            ICheckBox.Checked = True
            BCheckBox.Checked = True
        ElseIf RichTextBox1.SelectionFont.Italic = True Then
        ICheckBox.Checked = True
        ElseIf RichTextBox1.SelectionFont.Underline = True Then
        UCheckBox.Checked = True
        ElseIf RichTextBox1.SelectionFont.Strikeout = True Then
        SCheckBox.Checked = True
        Else
        UCheckBox.Checked = False
        SCheckBox.Checked = False
        ICheckBox.Checked = False
        BCheckBox.Checked = False
        End If
    End Sub
Posted
Updated 29-Nov-11 16:53pm
v3
Comments
Sergey Alexandrovich Kryukov 29-Nov-11 22:38pm    
VB or VB.NET?!!
--SA
Mathsquare 29-Nov-11 22:44pm    
Vb.net

What's the problem? You have a reasonable plan for a feature, just implement it. Yes, all such buttons should be checked/unckecked.

With WPF, use System.Windows.Controls.Primitives.ToggleButton, http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.togglebutton.aspx[^].

With System.Windows.Forms, such button can be easily implemented as a custom control, derived from System.Windows.Forms.Control. You can also simply use System.Windows.Forms.CheckBox.
See:
http://msdn.microsoft.com/en-us/library/system.windows.forms.buttonbase.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.aspx[^].


—SA
 
Share this answer
 
v2
Use ToolStrip Control from ToolBar.It provides the Button with Check and Uncheck facility.
Make CheckOnClick Property True for that buttons.
Use following code :
VB
'For Bold Text
        If ToolStripBoldButton.Checked Then
            txtNotePad.SelectionFont = SetTextBold
        Else
            txtNotePad.SelectionFont = SetTextRegular
        End If

Similarly you can use following code :
VB
'For Normal Text
 txtNotePad.SelectionFont = SetTextRegular
'For Italic Text
 txtNotePad.SelectionFont = SetTextItalic
'For Underline Text
 txtNotePad.SelectionFont = SetTextUnderline
'Here txtNotePad is the name of RichTextBox

I hope it will help you :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900