Пример #1
0
        /// <summary>
        /// Draws the background gradient image in the control based on the various gradient settings that are set for the control.  All drawing will
        /// be performed in memory-based device context before rendering onto the control to allow for flicker-free drawing.
        /// </summary>
        protected virtual void DrawBackGradientImage(Graphics gCtl)
        {
            Bitmap        bmpGradBackMem = null;
            Graphics      gGradBackMem   = null;
            GraphicsState origGraphState = null;

            try
            {
                // At the beginning of your drawing
                origGraphState = gCtl.Save();

                bmpGradBackMem = new Bitmap(this.Width, this.Height);
                gGradBackMem   = Graphics.FromImage(bmpGradBackMem);

                CoolGradientType BackGradTypeActive   = GetBackGradientType();
                Color            BackGradColor1Active = GetBackGradientColor(1);
                Color            BackGradColor2Active = GetBackGradientColor(2);
                float            fGradientSpan        = GetBackGradientSpan();
                Point            ptGradOffset         = GetBackGradientOffset();

                Rectangle rectBounds = new Rectangle(0, 0, this.Width, this.Height);

                if (BackGradColor1Active != Color.Transparent && BackGradTypeActive != CoolGradientType.None)
                {
                    CoolDraw.DrawGradientShape(CoolShape.Rectangle, BackGradTypeActive, gGradBackMem, BackGradColor1Active,
                                               BackGradColor2Active, rectBounds, Color.Transparent, 0, fGradientSpan, ptGradOffset.X, ptGradOffset.Y);
                }
                else
                {
                    Color?FillColor = null;
                    if (BackGradColor1Active != Color.Transparent)
                    {
                        FillColor = BackGradColor1Active;
                    }

                    CoolDraw.DrawShape(CoolShape.Rectangle, gGradBackMem, rectBounds, Color.Transparent, 0,
                                       0, 0, FillColor);
                }//end if

                Rectangle rectDraw = new Rectangle(0, 0, this.Width, this.Height);
                //gCtl.CompositingMode = CompositingMode.SourceCopy;
                gCtl.DrawImage(bmpGradBackMem, rectDraw);
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in DrawBackGradientImage function of DotCoolPanel control.");
            }
            finally
            {
                if (origGraphState != null)
                {
                    gCtl.Restore(origGraphState);
                }

                if (gGradBackMem != null)
                {
                    gGradBackMem.Dispose();
                }

                if (bmpGradBackMem != null)
                {
                    bmpGradBackMem.Dispose();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Draws the appropriate gradient check symbol in the box portion of the check control when the control is checked, according to the current
        /// state of the control.
        /// </summary>
        protected virtual void DrawCheckSymbol(Graphics gCtl)
        {
            Bitmap        bmpGradCheckMem = null;
            Graphics      gGradCheckMem   = null;
            GraphicsState origGraphState  = null;

            try
            {
                // At the beginning of your drawing
                origGraphState = gCtl.Save();

                bmpGradCheckMem = new Bitmap(CheckSize.Width, CheckSize.Height);
                gGradCheckMem   = Graphics.FromImage(bmpGradCheckMem);

                CoolGradientType CheckGradTypeActive   = GetCheckGradientType();
                Color            CheckGradColor1Active = GetCheckGradientColor(1);
                Color            CheckGradColor2Active = GetCheckGradientColor(2);
                float            fGradientSpan         = GetCheckGradientSpan();
                Point            ptGradOffset          = GetCheckGradientOffset();

                Color CheckBorderColorActive = GetCheckBorderColor();
                int   iBorderWidth           = CheckBorderWidth;

                Rectangle rectBounds = new Rectangle(Convert.ToInt32(iBorderWidth / 2), Convert.ToInt32(iBorderWidth / 2),
                                                     CheckSize.Width - iBorderWidth - 1,
                                                     CheckSize.Height - iBorderWidth - 1);

                Point ptCheckLocation = new Point(Convert.ToInt32(m_BoxBounds.Left) + GetBorderWidth() + CheckOffset.X,
                                                  Convert.ToInt32(m_BoxBounds.Top) + GetBorderWidth() + CheckOffset.Y);

                if (CheckGradColor1Active != Color.Transparent && CheckGradTypeActive != CoolGradientType.None)
                {
                    CoolDraw.DrawGradientShape(CheckShape, CheckGradTypeActive, gGradCheckMem, CheckGradColor1Active,
                                               CheckGradColor2Active, rectBounds, CheckBorderColorActive, iBorderWidth,
                                               fGradientSpan, ptGradOffset.X, ptGradOffset.Y,
                                               CheckRadius.X, CheckRadius.Y);
                }
                else
                {
                    Color?FillColor = null;
                    if (CheckGradColor1Active != Color.Transparent)
                    {
                        FillColor = CheckGradColor1Active;
                    }

                    CoolDraw.DrawShape(CheckShape, gGradCheckMem, rectBounds, CheckBorderColorActive, iBorderWidth,
                                       CheckRadius.X, CheckRadius.Y, FillColor);
                }//end if

                Rectangle rectDraw = new Rectangle(ptCheckLocation.X, ptCheckLocation.Y, CheckSize.Width, CheckSize.Height);

                gCtl.CompositingMode = CompositingMode.SourceOver;
                gCtl.DrawImage(bmpGradCheckMem, rectDraw);
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in DrawCheckSymbol function of DotCoolCheckBase control.");
            }
            finally
            {
                if (origGraphState != null)
                {
                    gCtl.Restore(origGraphState);
                }

                if (gGradCheckMem != null)
                {
                    gGradCheckMem.Dispose();
                }

                if (bmpGradCheckMem != null)
                {
                    bmpGradCheckMem.Dispose();
                }
            }
        }