© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
17 replies
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);
        }
        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);
        }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

windows forms text box
C#CC# / help
3y ago
Format text in file - Windows Forms
C#CC# / help
11mo ago
Windows Forms
C#CC# / help
13mo ago
Windows forms
C#CC# / help
4y ago