protected void OnCellPaint(TableLayoutCellPaintEventArgs e, bool isChecked)
 {
     using (QuickBitmap qbm = new QuickBitmap(e.CellBounds.Size))
     {
         qbm.Graphics.Clear(Color.Transparent);
         Rectangle newBound = new Rectangle(Point.Empty, e.CellBounds.Size);
         //base.OnCellPaint(new TableLayoutCellPaintEventArgs(qbm.Graphics, e.ClipRectangle, e.CellBounds, e.Column, e.Row));
         if (backBuffer != null && !backBuffer.Disposed)
         {
             qbm.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
             qbm.Graphics.DrawImage(backBuffer.Bitmap, newBound, e.CellBounds, GraphicsUnit.Pixel);
             qbm.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
         }
         qbm.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
         if (this.cellllll.ContainsKey(e.Column) && this.cellllll[e.Column].ContainsKey(e.Row))
         {
             FakeCheckBox fcb = this.GetCheckBox(e.Column, e.Row);
             if (fcb != null && fcb.Visible)
             {
                 Rectangle qbmRect;
                 if (this.CellBorderStyle == TableLayoutPanelCellBorderStyle.None)
                 {
                     qbmRect = new Rectangle(Point.Empty, e.CellBounds.Size);
                 }
                 else
                 {
                     qbmRect = new Rectangle(new Point(2, 2), e.CellBounds.Size);
                 }
                 this.DrawCheckBox(qbm.Graphics, newBound, fcb, isChecked);
             }
         }
         e.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
         e.Graphics.DrawImage(qbm.Bitmap, e.CellBounds, newBound, GraphicsUnit.Pixel);
     }
 }
        private void DrawCheckBox(Graphics g, Rectangle bound, FakeCheckBox fcb, CheckBoxState state)
        {
            Size      precalculatedSize = TextRenderer.MeasureText(g, fcb.Text, fcb.Font, new Size(bound.Width - 12, bound.Height), TextFormatFlags.PreserveGraphicsClipping | TextFormatFlags.Default);
            Size      TextSize          = new Size(Math.Min(precalculatedSize.Width, bound.Width - 12), Math.Min(precalculatedSize.Height, bound.Height));
            Rectangle textRect          = new Rectangle(new Point(bound.X + 12, bound.Y), TextSize);

            if (fcb.HighlightText)
            {
                using (Brush bru = new SolidBrush(Color.FromArgb(100, Color.White)))
                    g.FillRectangle(bru, textRect);
            }
            switch (state)
            {
            case CheckBoxState.CheckedDisabled:
                CheckBoxRenderer.DrawCheckBox(g, new Point(bound.Location.X, bound.Location.Y + 1), textRect, fcb.Text, fcb.Font, false, state);
                break;

            case CheckBoxState.UncheckedDisabled:
                CheckBoxRenderer.DrawCheckBox(g, new Point(bound.Location.X, bound.Location.Y + 1), textRect, fcb.Text, fcb.Font, false, state);
                break;

            case CheckBoxState.MixedDisabled:
                CheckBoxRenderer.DrawCheckBox(g, new Point(bound.Location.X, bound.Location.Y + 1), textRect, fcb.Text, fcb.Font, false, state);
                break;

            default:
                CheckBoxRenderer.DrawCheckBox(g, new Point(bound.Location.X, bound.Location.Y + 1), state);
                TextRenderer.DrawText(g, fcb.Text, fcb.Font, textRect, fcb.ForeColor, TextFormatFlags.PreserveGraphicsClipping | TextFormatFlags.Left);
                break;
            }
            //CheckBoxRenderer.DrawCheckBox(g, new Point(bound.Location.X, bound.Location.Y + 1), new Rectangle(bound.X + 11, bound.Y, bound.Width - 11, bound.Height), text, font, focused, state);
            //var theresult = TextRendererWrapper.WrapString(text, bound.Width - 11, this.Font, TextFormatFlags.Left);
        }
        private void Fcb_Invalidating(object sender, EventArgs e)
        {
            FakeCheckBox fcb = sender as FakeCheckBox;

            if (this.strChkBox.ContainsKey(fcb))
            {
                this.RedrawCell(this.strChkBox[fcb]);
            }
        }
        protected virtual void OnCellLeave(CellPointedEventArgs e)
        {
            this.CellLeave?.Invoke(this, e);
            FakeCheckBox fcb = GetCheckBox(e.Coordinate.Value.Column, e.Coordinate.Value.Row);

            if (fcb != null)
            {
                this.RedrawCell(e.Coordinate, fcb.Checked);
            }
        }
        public FakeCheckBox GetCheckBox(int column, int row)
        {
            FakeCheckBox result = null;

            if (this.cellllll.ContainsKey(column) && this.cellllll[column].ContainsKey(row))
            {
                result = this.cellllll[column][row];
            }
            return(result);
        }
 protected override void OnMouseUp(MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         this.isLeftMouseDown = false;
         if (this.lastKnownCoordinate != null)
         {
             FakeCheckBox fcb = this.GetCheckBox(this.lastKnownCoordinate.Value.Column, this.lastKnownCoordinate.Value.Row);
             if (fcb != null && fcb.Enabled)
             {
                 fcb.Checked = !fcb.Checked;
             }
         }
     }
     base.OnMouseDown(e);
 }
        public FakeCheckBox Add(int column, int row, string text, string name)
        {
            if (!this.cellllll.ContainsKey(column))
            {
                this.cellllll.Add(column, new Dictionary <int, FakeCheckBox>());
            }
            var something = this.cellllll[column];

            if (!something.ContainsKey(row))
            {
                FakeCheckBox fcb = new FakeCheckBox()
                {
                    Text = text, Name = name, ForeColor = this.ForeColor, Font = this.Font
                };
                fcb.Invalidating += this.Fcb_Invalidating;
                something.Add(row, fcb);
                this.strChkBox.Add(fcb, new TableLayoutPanelCellPosition(column, row));
                this.RedrawCell(column, row);
                this.Controls.Add(fcb);
                return(fcb);
            }
            return(null);
        }
 protected override void OnCellPaint(TableLayoutCellPaintEventArgs e)
 {
     using (QuickBitmap qbm = new QuickBitmap(e.CellBounds.Size))
     {
         qbm.Graphics.Clear(Color.Transparent);
         Rectangle newBound = new Rectangle(Point.Empty, e.CellBounds.Size);
         //base.OnCellPaint(new TableLayoutCellPaintEventArgs(qbm.Graphics, e.ClipRectangle, e.CellBounds, e.Column, e.Row));
         if (backBuffer != null && !backBuffer.Disposed)
         {
             qbm.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
             qbm.Graphics.DrawImage(backBuffer.Bitmap, newBound, e.CellBounds, GraphicsUnit.Pixel);
             qbm.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
         }
         qbm.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
         if (this.cellllll.ContainsKey(e.Column) && this.cellllll[e.Column].ContainsKey(e.Row))
         {
             FakeCheckBox fcb = this.GetCheckBox(e.Column, e.Row);
             if (fcb != null && fcb.Visible)
             {
                 if (fcb.Checked)
                 {
                     if (fcb.Enabled)
                     {
                         if (this.lastKnownCoordinate != null && this.lastKnownCoordinate.Value.Column == e.Column && this.lastKnownCoordinate.Value.Row == e.Row)
                         {
                             if (this.isLeftMouseDown)
                             {
                                 this.DrawCheckBox(qbm.Graphics, newBound, fcb, CheckBoxState.CheckedPressed);
                             }
                             else
                             {
                                 this.DrawCheckBox(qbm.Graphics, newBound, fcb, CheckBoxState.CheckedHot);
                             }
                         }
                         else
                         {
                             this.DrawCheckBox(qbm.Graphics, newBound, fcb, CheckBoxState.CheckedNormal);
                         }
                     }
                     else
                     {
                         this.DrawCheckBox(qbm.Graphics, newBound, fcb, CheckBoxState.CheckedDisabled);
                     }
                 }
                 else
                 {
                     if (fcb.Enabled)
                     {
                         if (this.lastKnownCoordinate != null && this.lastKnownCoordinate.Value.Column == e.Column && this.lastKnownCoordinate.Value.Row == e.Row)
                         {
                             if (this.isLeftMouseDown)
                             {
                                 this.DrawCheckBox(qbm.Graphics, newBound, fcb, CheckBoxState.UncheckedPressed);
                             }
                             else
                             {
                                 this.DrawCheckBox(qbm.Graphics, newBound, fcb, CheckBoxState.UncheckedHot);
                             }
                         }
                         else
                         {
                             this.DrawCheckBox(qbm.Graphics, newBound, fcb, CheckBoxState.UncheckedNormal);
                         }
                     }
                     else
                     {
                         this.DrawCheckBox(qbm.Graphics, newBound, fcb, CheckBoxState.UncheckedDisabled);
                     }
                 }
             }
         }
         e.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
         e.Graphics.DrawImage(qbm.Bitmap, e.CellBounds, newBound, GraphicsUnit.Pixel);
     }
 }