Click here to Skip to main content
12,950,399 members (63,050 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I want To draw on richtextbox ,so I found this code :

 private void IRTBDrawRectangle(Color RTBDrawColor, int RTBPointX, int RTBPointY, int RTBWidth, int RTBHeight)
            System.Drawing.Pen MyPen = new System.Drawing.Pen(RTBDrawColor);
            System.Drawing.Graphics FormGraphics = null;
            SolidBrush MySolidBrush = null;
            RTBHeight = RTBHeight * 1 + 2;
            if (RTBDrawColor.A > 64)
                MySolidBrush = new SolidBrush(Color.FromArgb(64, RTBDrawColor.R, RTBDrawColor.G, RTBDrawColor.B));
                MySolidBrush = new SolidBrush(RTBDrawColor);
            FormGraphics = this.richTextBox1.CreateGraphics();
            FormGraphics.DrawRectangle(MyPen, RTBPointX, RTBPointY, RTBWidth, RTBHeight);
            FormGraphics.FillRectangle(MySolidBrush, RTBPointX, RTBPointY, RTBWidth, RTBHeight);

// but when I scroll the Richtext up or down the rectangle (shape) which i have draw go away and disappeared .
i want it to be paint permanently .
Posted 3-Sep-12 1:41am
Updated 3-Sep-12 1:46am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Al-Samman Mahmoud 3-Sep-12 10:53am
Thank U I am Reading it right now.......
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


Call this.richTextBox1.Refresh() inside the method.

Al-Samman Mahmoud 3-Sep-12 10:53am
It's not about refresh I do refresh the rich text after calling method but the shape disappear after scrolling it's like it was just text remains but "shape" keep vanishing

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,829
CHill60 3,460
Maciej Los 2,953
Jochen Arndt 1,975
ppolymorphe 1,820

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 3 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100