Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Windows
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));
            }
            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 3-Sep-12 1:41am
Edited 3-Sep-12 1:46am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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

Solution 2

Hi,
 
Call this.richTextBox1.Refresh() inside the method.
 
Thanks!!
  Permalink  
Comments
Al-Samman Mahmoud at 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
0 Sergey Alexandrovich Kryukov 359
1 Richard MacCutchan 320
2 OriginalGriff 240
3 Jared Sanow 145
4 Snehasish_Nandy 115
0 Sergey Alexandrovich Kryukov 5,969
1 OriginalGriff 5,005
2 CPallini 2,473
3 Richard MacCutchan 1,547
4 Abhinav S 1,507


Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 3 Sep 2012
Copyright © CodeProject, 1999-2014
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