C#C
C#2y ago
OnkelTem

DrawString doesn't update text / Windows Forms

Hi. I'm new to C# development. I create a control on a form and want to print its ClientRectangle.
Whenever I resize the parent form, OnPaint gets called but text doesn't change. Yet the console message is of course changing. Why it happens?
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            e.Graphics.FillRectangle(Brushes.Black, ClientRectangle);
            Console.WriteLine($"-->{ClientRectangle}");
            e.Graphics.DrawString($"==>{ClientRectangle}", Font, Brushes.White, ClientRectangle);
        }
Was this page helpful?