Append text and image in RichTextBox

北城以北 提交于 2019-12-23 17:27:32

问题


For Append Text

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]);
    }
}

For Append Image

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

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

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

I do not know how can create RichTextBox like This image?


回答1:


You can create a 2 rows x 3 columns table and add the elements to the corresponding cells. If you don't want its borders to appear use the \brdrcf1 tag with white color from the color table. More about rtf tables: Using Tables in RTF



来源:https://stackoverflow.com/questions/11086041/append-text-and-image-in-richtextbox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!