title: How to make the richtextbox editable when drawn over the selection in it
body: <p>I have to provide the selection support for rich text box so I have created separate control and try to drawn over it using <code>paint()</code> method. I have done it but I am not able to edit the <code>rtbox</code> once done the drawing over it. Please find the below code I have used and share your ideas.</p>
  
  <p>Note : I suspect issue due to setting the <code>selectioncontrol</code> dock style as <code>Fill</code> but if I remove or changed then selection not drawn.</p>
  
  <pre><code>partial class Form1
  {
      /// &lt;summary&gt;
      /// Required designer variable.
      /// &lt;/summary&gt;
      private System.ComponentModel.IContainer components = null;
  
      /// &lt;summary&gt;
      /// Clean up any resources being used.
      /// &lt;/summary&gt;
      /// &lt;param name="disposing"&gt;true if managed resources should be disposed; otherwise, false.&lt;/param&gt;
      protected override void Dispose(bool disposing)
      {
          if (disposing &amp;&amp; (components != null))
          {
              components.Dispose();
          }
          base.Dispose(disposing);
      }
  
      #region Windows Form Designer generated code
  
      private GraphicCellControl graphiccell;
  
      /// &lt;summary&gt;
      /// Required method for Designer support - do not modify
      /// the contents of this method with the code editor.
      /// &lt;/summary&gt;
      private void InitializeComponent()
      {
  
          #region picturebox
  
          this.BackColor = Color.Aquamarine;
  
          var selectBtn = new Button();
          selectBtn.Size = new Size(100, 30);
          selectBtn.Location = new Point(10, 10);
          selectBtn.Text = "Click";
          selectBtn.Click += selectBtn_Click;
  
          //var picturebox = new PictureBox();
          //picturebox.Size = new Size(140, 110);
          //picturebox.Location = new Point(4, 4);
          //picturebox.SizeMode = PictureBoxSizeMode.StretchImage;
          //picturebox.Image = new Bitmap(@"..\..\Data\picture.png");
  
          var richtextbox = new RichTextBox();
          richtextbox.Size = new Size(140, 110);
          richtextbox.Location = new Point(4, 4);
          richtextbox.Text = "Texting information";
  
          graphiccell = new GraphicCellControl();
          graphiccell.Location = new Point(50, 200);
          graphiccell.Size = new Size(150, 120);
          graphiccell.Controls.Add(richtextbox);
          this.Controls.Add(graphiccell);
          this.Controls.Add(selectBtn);
  
          #endregion
  
      }
  
      void selectBtn_Click(object sender, EventArgs e)
      {
          graphiccell.IsSelected = !graphiccell.IsSelected;
      }
  
      #endregion
  }
  
  public class GraphicCellControl : Control
  {
      private SelectionControl selectionControl;
      public GraphicCellControl()
      {
          selectionControl = new SelectionControl();
      }
  
      private bool isselected;
      public bool IsSelected
      {
          get { return isselected; }
          set
          {
              isselected = value;
              if (isselected &amp;&amp; !this.Controls.Contains(selectionControl))
              {
                  this.Controls.Add(selectionControl);
                  selectionControl.BringToFront();
              }
              else if (!isselected &amp;&amp; this.Controls.Contains(selectionControl))
                  this.Controls.Remove(selectionControl);
          }
      }
  }
  
  public class SelectionControl : Control
  {
      public SelectionControl()
      {
          SetStyle(ControlStyles.AllPaintingInWmPaint |
                   ControlStyles.UserPaint | ControlStyles.Opaque |
                   ControlStyles.SupportsTransparentBackColor, true);
          Dock = DockStyle.Fill;
         // Anchor = AnchorStyles.Left | AnchorStyles.Top;
          BackColor = Color.Transparent;
      }
  
      protected override void OnPaint(PaintEventArgs e)
      {
          base.OnPaint(e);
          e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
          e.Graphics.DrawRectangle(new Pen(Color.Gray, 1), 4, 4, this.Size.Width - 10, this.Size.Height - 10);
  
          e.Graphics.FillEllipse(Brushes.White, 0, 0, 8, 8);
          e.Graphics.FillEllipse(Brushes.White, 0, (this.Size.Height - 10) / 2, 8, 8);
          e.Graphics.FillEllipse(Brushes.White, 0, this.Size.Height - 10, 8, 8);
          e.Graphics.FillEllipse(Brushes.White, (this.Size.Width - 10) / 2, 0, 8, 8);
          e.Graphics.FillEllipse(Brushes.White, (this.Size.Width - 10) / 2, this.Size.Height - 10, 8, 8);
          e.Graphics.FillEllipse(Brushes.White, this.Size.Width - 10, 0, 8, 8);
          e.Graphics.FillEllipse(Brushes.White, this.Size.Width - 10, (this.Size.Height - 10) / 2, 8, 8);
          e.Graphics.FillEllipse(Brushes.White, this.Size.Width - 10, this.Size.Height - 10, 8, 8);
  
          e.Graphics.DrawEllipse(new Pen(Color.DarkGray, 2), 0, 0, 8, 8);
          e.Graphics.DrawEllipse(new Pen(Color.DarkGray, 2), 0, (this.Size.Height - 10) / 2, 8, 8);
          e.Graphics.DrawEllipse(new Pen(Color.DarkGray, 2), 0, this.Size.Height - 10, 8, 8);
          e.Graphics.DrawEllipse(new Pen(Color.DarkGray, 2), (this.Size.Width - 10) / 2, 0, 8, 8);
          e.Graphics.DrawEllipse(new Pen(Color.DarkGray, 2), (this.Size.Width - 10) / 2, this.Size.Height - 10, 8, 8);
          e.Graphics.DrawEllipse(new Pen(Color.DarkGray, 2), this.Size.Width - 10, 0, 8, 8);
          e.Graphics.DrawEllipse(new Pen(Color.DarkGray, 2), this.Size.Width - 10, (this.Size.Height - 10) / 2, 8, 8);
          e.Graphics.DrawEllipse(new Pen(Color.DarkGray, 2), this.Size.Width - 10, this.Size.Height - 10, 8, 8);
      }
  }
  </code></pre>