Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want To draw on richtextbox ,so I found this code :

C#
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));
           }
           else
           {
               MySolidBrush = new SolidBrush(RTBDrawColor);
           }
           FormGraphics = this.richTextBox1.CreateGraphics();
           FormGraphics.DrawRectangle(MyPen, RTBPointX, RTBPointY, RTBWidth, RTBHeight);
           FormGraphics.FillRectangle(MySolidBrush, RTBPointX, RTBPointY, RTBWidth, RTBHeight);
           MyPen.Dispose();
           FormGraphics.Dispose();

       }

// 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
Updated 3-Sep-12 1:46am
v2

 
Share this answer
 
Comments
Al-Samman Mahmoud 3-Sep-12 10:53am    
Thank U I am Reading it right now.......
Hi,

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

Thanks!!
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900