本文介绍了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
推荐答案
'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的字体样式按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!