title: c# Draw rectangle around control when hovered
body: <p>I am overiding <code>OnPaint</code> method of <code>Control</code> class to create emoticon. The emoticons have been created. But I'm to add a rectangle around it when it is hovered.</p>
  
  <pre><code>public class EmoticonControl : Control
  {
      public EmoticonControl(string unicode, Image image)
      {
          this.unicode = unicode;
          this.image = image;
      }
  
      protected override void OnPaint(PaintEventArgs e)
      {
          Graphics graphics = e.Graphics;
          Rectangle clipRectangle = e.ClipRectangle;
          graphics.DrawImage(this.image, 0, 0, this.Size.Width, this.Size.Height);
  
          // When hovered
          Brush brush = new SolidBrush(this.selectedColor);
          graphics.FillRectangle(new SolidBrush(selectionColor), clipRectangle);
          graphics.DrawRectangle(new Pen(selectionBorderColor), clipRectangle.X, clipRectangle.Y, clipRectangle.Width - 1, clipRectangle.Height - 1);
          //
      }
      private string unicode;
      private Image image;
  
      private Color selectedColor = SystemColors.Highlight;
      private Color selectionColor = Color.FromArgb(50, 0, 0, 150);
      private Color selectionBorderColor = SystemColors.Highlight;
  }
  </code></pre>