コード例 #1
0
        /// <summary>
        /// Draws the check symbol image for the control in the box portion of the check control.  The image will be drawn and rendered onto the
        /// control based on the various check symbol image settings that are set in the control.
        /// NOTE: When an image check symbol is used, it will override the gradient check symbol settings and be displayed instead of the gradient
        /// check symbol.
        /// </summary>
        /// <param name="gCtl"></param>
        protected override void DrawControlImage(Graphics gCtl)
        {
            GraphicsState origGraphState = null;

            try
            {
                if (m_CheckState == CheckState.Unchecked)
                {
                    return;
                }

                origGraphState       = gCtl.Save();
                gCtl.CompositingMode = CompositingMode.SourceOver;

                Image imgActive = GetImage();

                if (imgActive != null)
                {
                    Point ptCheckLocation = new Point(Convert.ToInt32(m_BoxBounds.Left) + GetBorderWidth() + GetImageOffset().X,
                                                      Convert.ToInt32(m_BoxBounds.Top) + GetBorderWidth() + GetImageOffset().Y);

                    CoolDraw.DrawImage(GetImage(), gCtl, new Rectangle(0, 0, this.Width, this.Height), GetImageAlign(), ptCheckLocation,
                                       true, GetImageTransColor());
                }//end if
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in DrawControlImage function of DotCoolCheckBase class.");
            }
            finally
            {
                if (origGraphState != null)
                {
                    gCtl.Restore(origGraphState);
                }
            }
        }
コード例 #2
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();
                }
            }
        }
コード例 #3
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();
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Draws an elliptical style of gradient in the specified region passed to the function.  The ellipitical gradient will be drawn using the
        /// starting and ending colors specified in the function's parameters.
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="gradColor1"></param>
        /// <param name="gradColor2"></param>
        /// <param name="oOutputData"></param>
        /// <param name="blDrawCircle"></param>
        public static void DrawEllipsisGradient(Graphics graphics, Color gradColor1, Color gradColor2, object oOutputData, bool blDrawCircle = false)
        {
            GraphicsPath      pathEllipse   = null;
            PathGradientBrush pathGradBrush = null;

            try
            {
                RectangleF   rectBounds;
                GraphicsPath pathOutput = null;

                GetOutputDataObjects(oOutputData, out rectBounds, out pathOutput);

                SizeF szEllipse;

                //The largest dimension of the specified region will be used to determine the diameter of the circle to draw.
                float fCircLen;

                if (blDrawCircle)
                {
                    if (rectBounds.Width > rectBounds.Height)
                    {
                        fCircLen = rectBounds.Width;
                    }
                    else
                    {
                        fCircLen = rectBounds.Height;
                    }

                    szEllipse = new SizeF(fCircLen * 1.5f, fCircLen * 1.5f);
                }
                else
                {
                    szEllipse = new SizeF(rectBounds.Width * 2, rectBounds.Height * 2);
                }//end if


                // Create a path that consists of a single ellipse.
                pathEllipse = new GraphicsPath();
                pathEllipse.AddEllipse(0, 0, szEllipse.Width, szEllipse.Height);

                // Use the path to construct a brush.
                pathGradBrush = new PathGradientBrush(pathEllipse);

                // Set the color at the center of the path to first gradient color.
                pathGradBrush.CenterColor = gradColor1;

                // Set the color along the entire boundary of the path to second gradient color.
                Color[] colors = { gradColor2 };
                pathGradBrush.SurroundColors = colors;

                if (pathOutput == null)
                {
                    Bitmap   bmpMemory = new Bitmap(Convert.ToInt32(szEllipse.Width), Convert.ToInt32(szEllipse.Height));
                    Graphics gMemory   = Graphics.FromImage(bmpMemory);

                    //Draws the ellipitical gradient in a expanded region in memory, so that the desired region of the ellipsis gradient can be
                    //rendered onto the device context (paintable surface/display) of the control's UI.
                    gMemory.FillEllipse(pathGradBrush, 0, 0, bmpMemory.Width, bmpMemory.Height);
                    gMemory.Dispose();

                    RectangleF rectSrc, rectDest;

                    float fSrcX = (bmpMemory.Width - rectBounds.Width) / 2;
                    float fSrcY = (bmpMemory.Height - rectBounds.Height) / 2;

                    rectSrc  = new RectangleF(fSrcX, fSrcY, rectBounds.Width, rectBounds.Height);
                    rectDest = new RectangleF(rectBounds.Left, rectBounds.Top, rectBounds.Width, rectBounds.Height);

                    //Draws a cropped region of the center-most area of the ellipitical gradient in the memory-resident image which will be
                    //rendered on the control's UI display.  This will result in producing the desired gradient effect for the control.
                    graphics.DrawImage(bmpMemory, rectDest, rectSrc, GraphicsUnit.Pixel);
                    bmpMemory.Dispose();
                }
                else
                {
                    Bitmap   bmpMemory = new Bitmap(Convert.ToInt32(szEllipse.Width), Convert.ToInt32(szEllipse.Height));
                    Graphics gMemory   = Graphics.FromImage(bmpMemory);

                    Rectangle    rectBoundsGrad = new Rectangle(Convert.ToInt32(rectBounds.Left), Convert.ToInt32(rectBounds.Top), Convert.ToInt32(rectBounds.Width * 3), Convert.ToInt32(rectBounds.Height * 3));
                    GraphicsPath pathGrad       = CoolDraw.GetRoundedRectPath(rectBoundsGrad, 10, 10, 0);

                    //Draws the ellipitical gradient in a expanded region in memory, so that the desired region of the ellipsis gradient can be
                    //rendered onto the device context (paintable surface/display) of the control's UI.
                    gMemory.FillPath(pathGradBrush, pathGrad);
                    gMemory.Dispose();

                    RectangleF rectSrc, rectDest;

                    float fSrcX = (bmpMemory.Width - rectBounds.Width) / 2;
                    float fSrcY = (bmpMemory.Height - rectBounds.Height) / 2;

                    rectSrc  = new RectangleF(fSrcX, fSrcY, rectBounds.Width, rectBounds.Height);
                    rectDest = new RectangleF(rectBounds.Left, rectBounds.Top, rectBounds.Width, rectBounds.Height);

                    bmpMemory.MakeTransparent();

                    //Draws a cropped region of the center-most area of the ellipitical gradient in the memory-resident image which will be
                    //rendered on the control's UI display.  This will result in producing the desired gradient effect for the control.
                    graphics.DrawImage(bmpMemory, rectDest, rectSrc, GraphicsUnit.Pixel);
                    bmpMemory.Dispose();
                }//end if
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in DrawEllipsisGradient function of CoolGradient class.");
            }
            finally
            {
                if (pathEllipse != null)
                {
                    pathEllipse.Dispose();
                }

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