Skip to content

Commit 1ecd7fa

Browse files
committed
Preserve zoom factor when setting RichTextBox RTF
Assigning to the RichTextBox.Rtf property resets the zoom factor to 1.0. This change saves and restores the original zoom factor after setting the RTF. Also updates the XML doc for maxLogLines to reflect the correct upper limit of 2048.
1 parent 9dda254 commit 1ecd7fa

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Serilog.Sinks.RichTextBox.WinForms.Colored/Sinks/RichTextBoxForms/Extensions/RichTextBoxExtensions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static void SetRtf(this RichTextBox richTextBox, string rtf, bool autoScr
6868
private static void SetRtfInternal(RichTextBox richTextBox, string rtf, bool autoScroll)
6969
{
7070
richTextBox.Suspend();
71-
71+
var originalZoomFactor = richTextBox.ZoomFactor;
7272
var scrollPoint = new Point();
7373

7474
if (!autoScroll)
@@ -78,6 +78,12 @@ private static void SetRtfInternal(RichTextBox richTextBox, string rtf, bool aut
7878

7979
richTextBox.Rtf = rtf;
8080

81+
// Re-apply the zoom level, as assigning to the Rtf property resets it back to 1.0.
82+
if (Math.Abs(richTextBox.ZoomFactor - originalZoomFactor) > float.Epsilon)
83+
{
84+
richTextBox.ZoomFactor = originalZoomFactor;
85+
}
86+
8187
if (!autoScroll)
8288
{
8389
SendMessage(richTextBox.Handle, EM_SETSCROLLPOS, 0, ref scrollPoint);

Serilog.Sinks.RichTextBox.WinForms.Colored/Sinks/RichTextBoxForms/RichTextBoxSinkOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class RichTextBoxSinkOptions
3232
/// </summary>
3333
/// <param name="theme">The colour theme applied when rendering individual message tokens.</param>
3434
/// <param name="autoScroll">When <c>true</c> (default) the target control scrolls automatically to the most recent log line.</param>
35-
/// <param name="maxLogLines">Maximum number of log events retained in the in-memory circular buffer and rendered in the control. Must be between 1 and 10,000 (default: 256).</param>
35+
/// <param name="maxLogLines">Maximum number of log events retained in the in-memory circular buffer and rendered in the control. Must be between 1 and 2048 (default: 256).</param>
3636
/// <param name="flushInterval">Timeout, in milliseconds, after which buffered events are flushed to the control if a batch has not yet been triggered. Must be between 250ms and 30 seconds (default: 500ms).</param>
3737
/// <param name="outputTemplate">Serilog output template that controls textual formatting of each log event.</param>
3838
/// <param name="formatProvider">Optional culture-specific or custom formatting provider used when rendering scalar values; <c>null</c> for the invariant culture.</param>

0 commit comments

Comments
 (0)