/// <summary> /// Overrides the paint method to be able to draw custom boxes /// </summary> /// <param name="e"></param> protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; g.Clear(BackColor); //Makes it look nice g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighQuality; Rectangle box = ClientRectangle; //One pixel in on each side, otherwise the outline gets drawn out of the bounding box box.Inflate(-1, -1); //This check is for the designer if (currentBackgroundColor == null) { SetColors(); } //Fill the background of the checkbox's circle Drawer.FillRoundedRectangle(g, new SolidBrush(currentBackgroundColor.ToColor()), box, cornerRadius); //Draw the outline Drawer.DrawRoundedRectangle(g, new Pen(currentBorderColor.ToColor(), 2), box, cornerRadius); //Draw the text slightly offset and in the middle vertically TextRenderer.DrawText(g, Text, Font, new Point(20, 3), currentTextColor.ToColor()); //Compositing mode for drawing the image g.CompositingMode = CompositingMode.SourceOver; //This check is for the designer if (images[0] != null) { Bitmap image = images[currentImage]; if (rotating) { //Rotates the image if required image = RotateImage(image, imageAngle); } g.DrawImage(image, 8, 8, 10, 10); } //Resets the interpolation mode g.InterpolationMode = InterpolationMode.HighQualityBicubic; }