RichTextBox で文字の装飾、画像の埋め込みを行う

RichTextBox の RTF を操作することで文字の装飾や画像の埋め込みができるようになる。

f:id:dechnostick:20140819000803g:plain

文字の装飾は

                buffer.SelectionColor = Color.Red
                buffer.SelectionFont = New Font(buffer.SelectionFont.FontFamily,
                                                fontSize, FontStyle.Bold)

といった形で行う。

画像はいったん RTF 形式で保存したものをテキストエディタで開いて画像部分を抜き出し、これを該当部分にセットすることで埋め込む。

        RichTextBox1.SelectedRtf = Converter.RTFHeader & Converter.Hashtable(key) & Converter.RTFFooter

ソースはこちら
https://github.com/dechnostick/RTFEditSample