问题描述
从标题中可以看出,Im在RichTexBox控件的选定文本中分配和删除格式样式有点问题。我知道如何使文本单独粗体/斜体/下划线,但不是这些的组合。我知道可以通过角色来实现这个角色的方式,但是这在接口上看起来很耗时。如果可以毫不费力地在写字板上完成,我确定它可以在这里实现!
是否没有这样的方法或存在,可以让我添加或从RichTextBox.SelectedFont中删除一个样式
解除方案我知道如何使文本单独粗体/斜体/下划线,但不是这些的组合。我知道可以通过角色来实现这个角色的方式,但是这在接口上看起来很耗时。如果可以毫不费力地在写字板上完成,我确定它可以在这里实现!
是否没有这样的方法或存在,可以让我添加或从RichTextBox.SelectedFont中删除一个样式
解除方案除非我完全误解了
//获取当前的文本选择或插入点之后输入的文本。
//根据选择的字体创建新的字体,使其为粗体和下划线
//将新字体应用于当前选中的文本(或插入点处的新文本
Font currFont = richTextBox.SelectionFont;
Font boldUnderFont = new Font(currFont,FontStyle.Bold | FontStyle.Underline);
richTextBox.SelectionFont = boldUnderFont;
As you can tell from the title, Im having a bit of issue regarding assigning and removing format styles to and from selected text in the RichTexBox control.
I know how to make text individually Bold/Italic/Underline, but not a combination of these. I know of ways that can achieve this character by character, but this would seem time-consuming on the interface. If it can be effortlessly done in Wordpad, Im sure it can be achieved here!
Is there no such method or such that exists that can allow me to "add" or "remove" a style from RichTextBox.SelectedFont?
Unless I am completely misunderstanding the question
// Get the current text selection or to text entered after the insertion point.
// Build new font based on the selection font, make it both Bold and Underline
// Apply new font to currently selected text (or for new text at insertion point
Font currFont = richTextBox.SelectionFont;
Font boldUnderFont = new Font(currFont, FontStyle.Bold | FontStyle.Underline);
richTextBox.SelectionFont = boldUnderFont;
这篇关于Winforms RichtextBox粗体/斜体/下划线格式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!