選択部分のフォントを変更して、これを複数のRichTextBoxで同期させます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
public partial class SyncRichTextBox : UserControl { void SetFont(Font newFont, Color newColor) { int start = SelectionStart; int length = SelectionLength; List<FontInfo> fontInfos = new List<FontInfo>(); RichTextBox r = new RichTextBox(); r.SelectedRtf = SelectedRtf; if (newFont != null) { r.SelectAll(); r.SelectionFont = newFont; } if (newColor != Color.Empty) { r.SelectAll(); r.SelectionColor = newColor; } r.SelectAll(); string rtf = r.SelectedRtf; r.Dispose(); if (SelectedRtf == rtf) return; if (SetSelectedRtf(rtf, "SetFontAndColor")) { var buf = Data.GetUndobuf(); buf.newSelectionStart = start; buf.newSelectionLength = length; SelectionStart = start; SelectionLength = length; } } public Font SelectionFont { get { return richTextBoxEx1.SelectionFont; } set { SetFont(value, Color.Empty); } } } |