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 .