vb.net的richtextbox的字体样式按钮 [英] font style buttons for richtextbox for vb.net

查看:234
本文介绍了vb.net的richtextbox的字体样式按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

字体样式按钮的含义是链接粗体,下划线等.我希望您可以单击这些按钮,然后再使用粗体和下划线,然后将字体样式显示为粗体和下划线.我尝试执行此操作,但是这太麻烦了,但是我还是希望可以选中或取消选中按钮.

所以请您帮我这几行代码

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

推荐答案

出什么问题了?您为功能制定了合理的计划,只需实施即可.是的,应该检查/取消所有此类按钮.

对于WPF,请使用System.Windows.Controls.Primitives.ToggleButton http://msdn.microsoft. com/en-us/library/system.windows.controls.primitives.togglebutton.aspx [ 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
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


使用ToolBar中的ToolStrip控件.它为Button提供了Check和Uncheck功能.
使该按钮的CheckOnClick属性为True.
使用以下代码:
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 :)


这篇关于vb.net的richtextbox的字体样式按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆