Unexpected (buggy?) behavior of RichTextBox when ZoomFactor is 2.0
-
Hi, all, I've stumbled upon a behavior of the .NET RichTextBox that I think is a bug, and I wanted somebody to do a sanity check before I report this to MS. Below is a code listing. It displays a form with a RichTextBox control in it. Ctrl++ and Ctrl+- increase/decrease zoom. Space and Backspace keys change content of the text box. Currently, zoom step is 0.5. Notice that when zoom factor is 2.0 (you can make it that by pressing Ctrl++ twice), the text box doesn't retain the zoom factor when its content changes. When you uncomment MessageBox statement in DisplayText (uses Clear() method of the text box class) method, you can more glimpse of the weird behavior. It is actually different with the MessageBox there. Increase zoom to 2.0 by pressing Ctrl++ twice and then press Space or Backspace repeatedly and notice zoom factor change from 2.0 to 1.0 to 2.0 to 1.0, … After that, change the zoom step to, say, 0.3 (zoom factor doesn't become 2.0 with this step), and notice that the box behaves as expected (the zoom factor remains as set). Is this a bug or reflection of my wrong expectations? Thanks ---------------------------------- using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; namespace BugInZoomFactor { /// /// Summary description for Form2. /// public class BugInZoomFactorForm : System.Windows.Forms.Form { private System.Windows.Forms.RichTextBox richTextBox1; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; private float zoomFactor = 1.0f; private float zoomStep = 0.5f; public BugInZoomFactorForm() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // this.KeyPreview = true; DisplayText("Initial text"); } private void DisplayText(string text) { richTextBox1.Clear(); richTextBox1.ZoomFactor = zoomFactor; //MessageBox.Show("control's zoom factor is " + richTextBox1. ZoomFactor.ToString()); richTextBox1.AppendText(text); } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows F
-
Hi, all, I've stumbled upon a behavior of the .NET RichTextBox that I think is a bug, and I wanted somebody to do a sanity check before I report this to MS. Below is a code listing. It displays a form with a RichTextBox control in it. Ctrl++ and Ctrl+- increase/decrease zoom. Space and Backspace keys change content of the text box. Currently, zoom step is 0.5. Notice that when zoom factor is 2.0 (you can make it that by pressing Ctrl++ twice), the text box doesn't retain the zoom factor when its content changes. When you uncomment MessageBox statement in DisplayText (uses Clear() method of the text box class) method, you can more glimpse of the weird behavior. It is actually different with the MessageBox there. Increase zoom to 2.0 by pressing Ctrl++ twice and then press Space or Backspace repeatedly and notice zoom factor change from 2.0 to 1.0 to 2.0 to 1.0, … After that, change the zoom step to, say, 0.3 (zoom factor doesn't become 2.0 with this step), and notice that the box behaves as expected (the zoom factor remains as set). Is this a bug or reflection of my wrong expectations? Thanks ---------------------------------- using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; namespace BugInZoomFactor { /// /// Summary description for Form2. /// public class BugInZoomFactorForm : System.Windows.Forms.Form { private System.Windows.Forms.RichTextBox richTextBox1; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; private float zoomFactor = 1.0f; private float zoomStep = 0.5f; public BugInZoomFactorForm() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // this.KeyPreview = true; DisplayText("Initial text"); } private void DisplayText(string text) { richTextBox1.Clear(); richTextBox1.ZoomFactor = zoomFactor; //MessageBox.Show("control's zoom factor is " + richTextBox1. ZoomFactor.ToString()); richTextBox1.AppendText(text); } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows F
I'm seeing this behavior too, odd. I don't see anything wrong with your code right off hand (hey, just have to check before filing a bug ;)) and looking at the IL for the
RichText.set_ZoomFactor
(and a subsequent call to a private method) doesn't show any calculation bugs either. I'm guessing this is actually a problem with the Rich Edit common control somewhere in theEM_SETZOOM
message handler. So, googling for "Rich Edit" EM_SETZOOM[^] shows you're not the only one! Feel free to report, though. Maybe someone hasn't yet. Never know.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----