Exemple #1
0
        void DrawCheckOnly(PaintEventArgs e, LayoutData layout, ColorData colors, Color checkColor, Color checkBackground, bool disabledColors)
        {
            // check
            //
            if (Checked)
            {
                if (!Enabled && disabledColors)
                {
                    checkColor = colors.buttonShadow;
                }
                else if (CheckState == CheckState.Indeterminate && disabledColors)
                {
                    checkColor = SystemInformation.HighContrast ? colors.highlight :
                                 colors.buttonShadow;
                }

                Rectangle fullSize = layout.checkBounds;

                if (fullSize.Width == flatCheckSize)
                {
                    fullSize.Width++;
                    fullSize.Height++;
                }

                fullSize.Width++;
                fullSize.Height++;
                if (checkImage == null || checkImage.Width != fullSize.Width || checkImage.Height != fullSize.Height)
                {
                    if (checkImage != null)
                    {
                        checkImage.Dispose();
                        checkImage = null;
                    }

                    // We draw the checkmark slightly off center to eliminate 3-D border artifacts,
                    // and compensate below
                    NativeMethods.RECT rcCheck   = NativeMethods.RECT.FromXYWH(0, 0, fullSize.Width, fullSize.Height);
                    Bitmap             bitmap    = new Bitmap(fullSize.Width, fullSize.Height);
                    Graphics           offscreen = Graphics.FromImage(bitmap);
                    offscreen.Clear(Color.Transparent);
                    IntPtr dc = offscreen.GetHdc();
                    try {
                        SafeNativeMethods.DrawFrameControl(new HandleRef(offscreen, dc), ref rcCheck,
                                                           NativeMethods.DFC_MENU, NativeMethods.DFCS_MENUCHECK);
                    }
                    finally {
                        offscreen.ReleaseHdcInternal(dc);
                    }
                    offscreen.Dispose();
                    bitmap.MakeTransparent();
                    checkImage = bitmap;
                }

                fullSize.Y -= 1;
                Region original = e.Graphics.Clip;
                ControlPaint.DrawImageColorized(e.Graphics, checkImage, fullSize, checkColor);
            }
        }