c# - 在 RichTextBox 中附加文本和图像

标签 c# richtextbox

用于附加文本

private void AddText(string text)
{
    string[] str = text.Split(new string[] { ";" },
        StringSplitOptions.RemoveEmptyEntries);

    if (str.Length == 2)
    {
        richTextBox1.DeselectAll();
        richTextBox1.SelectionFont = new Font(richTextBox1.SelectionFont, FontStyle.Bold);
        richTextBox1.AppendText(Environment.NewLine + str[0] + ";");
        richTextBox1.SelectionFont = new Font(richTextBox1.SelectionFont, FontStyle.Regular);
        richTextBox1.AppendText(str[1]);
    }
}

用于附加图像

Image image = Image.FromFile("Logo.jpg");

// Put the image on the clipboard
Clipboard.SetImage(image);

//// Paste it into the rich tetx box.
richTextBox1.Paste();

我不知道如何创建像 This image 这样的 RichTextBox? enter image description here

最佳答案

您可以创建一个 2 行 x 3 列的表格并将元素添加到相应的单元格中。如果您不希望其边框出现,请使用颜色表中的白色 \brdrcf1 标签。 有关 rtf 表的更多信息: Using Tables in RTF

关于c# - 在 RichTextBox 中附加文本和图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11086041/

相关文章:

c# - Rx .Net TestScheduler - 立即执行计划的事件

wpf - 为什么在持久化的 WPF RichTextBox 中有自复制的大括号?

wpf - 从在 wpf 中显示图像的 Richtextbox 复制表情符号 "text"

c# - 加快将 rtf 转换为纯文本的速度

wpf - 从/向 SQL 保存和检索 RichTextBox.Document?

c# - 使用各种类属性返回 Expression<>

c# - 如何在代码中将图像文件添加到图像列表?

c# - Entity Framework 自动重命名多对多表而无需任何更改

c# - 如何使用 AutoFac 解析正确的记录器类型?

c# - WPF TextBox 和 RichTextBox 的组合