vb.net 使字体粗体/斜体/下划线 Visual Basic
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13113173/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Make Font Bold/Italic/Underline Visual Basic
提问by Ds.109
Ok I already have a Font Dialog that changes the font of the richtextbox and it works (although I don't know how to make the apply button of the dialog work)
好的,我已经有一个 Font Dialog 可以更改 Richtextbox 的字体并且它可以工作(虽然我不知道如何使对话框的应用按钮工作)
I also made 4 buttons for Bold, Underline, Strikethrough, and Italic.
我还为粗体、下划线、删除线和斜体制作了 4 个按钮。
The method I have found most people using is
我发现大多数人使用的方法是
Dim boldf as NewFont(....)
and then applying it to the selected text.
然后将其应用于所选文本。
Problem with that is that it changes the font to only Bold, it doesn't add it to the existing style.
问题在于它将字体更改为仅粗体,而不是将其添加到现有样式中。
Please advise.
请指教。
采纳答案by Steve
Private Sub andlowitwasbold_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles andlowitwasbold.Click
If RichTextBox1.SelectionFont.Bold Then 'its already bold, so set it to regular
RichTextBox1.SelectionFont = New Font(RichTextBox1.Font.FontFamily, RichTextBox1.Font.Size, FontStyle.Regular)
Else 'make it bold
RichTextBox1.SelectionFont = New Font(RichTextBox1.Font.FontFamily, RichTextBox1.Font.Size, FontStyle.Bold)
End If
End Sub
回答by Milk Tea
Another way to do this is:
另一种方法是:
RichTextBox1.SelectionFont.Bold = Not(RichTextBox1.SelectionFont.Bold)