Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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
 
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 29-Nov-11 16:31pm
Edited 29-Nov-11 17:53pm
v3
Comments
SAKryukov at 29-Nov-11 22:38pm
   
VB or VB.NET?!!
--SA
Mathsquare at 29-Nov-11 22:44pm
   
Vb.net
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Use ToolStrip Control from ToolBar.It provides the Button with Check and Uncheck facility.
Make CheckOnClick Property True for that buttons.
Use following code :
'For Bold Text
        If ToolStripBoldButton.Checked Then
            txtNotePad.SelectionFont = SetTextBold
        Else
            txtNotePad.SelectionFont = SetTextRegular
        End If
Similarly you can use following code :
'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 Smile | :)
  Permalink  
v2

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



Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 30 Nov 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100