Пример #1
0
        /// <summary>
        /// Draws the gradient background image of the DotCoolNativeButton according to the background gradient settings that are set for the control.
        /// NOTE: The DotCoolNativeButton will use the button's background image, rather than the paint event handlers to render the background gradient
        /// image so that the button's native functionality can be maintained.
        /// </summary>
        protected virtual void DrawGradientBackgroundImage()
        {
            Bitmap   bmpGradBackMem = null;
            Graphics gGradBackMem   = null;
            Graphics gGradBack      = null;

            try
            {
                bmpGradBackMem = new Bitmap(ClientRectangle.Width, ClientRectangle.Height);
                gGradBackMem   = Graphics.FromImage(bmpGradBackMem);

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

                if (BackGradTypeActive == CoolGradientType.None || BackGradColor1Active == Color.Transparent)
                {
                    ClearGradientBackgroundImage();
                    return;
                }
                else
                {
                    CoolGradient.DrawGradient(BackGradTypeActive, gGradBackMem, BackGradColor1Active, BackGradColor2Active, ClientRectangle,
                                              fGradSpan, ptGradOffset.X, ptGradOffset.Y);
                }

                this.BackgroundImage = new Bitmap(ClientRectangle.Width, ClientRectangle.Height);
                gGradBack            = Graphics.FromImage(this.BackgroundImage);
                gGradBack.DrawImage(bmpGradBackMem, ClientRectangle);

                this.Refresh();
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in DrawGradientBackgroundImage function of DotCoolNativeButton control.");
            }
            finally
            {
                if (gGradBackMem != null)
                {
                    gGradBackMem.Dispose();
                }

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

                if (bmpGradBackMem != null)
                {
                    bmpGradBackMem.Dispose();
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Gets the appropriate background gradient span value of the control based on the control's current state.
 /// </summary>
 /// <returns></returns>
 protected virtual float GetBackGradientSpan()
 {
     try
     {
         if (!this.Enabled && BackGradientSettingsDisabled.GradientColor1 != Color.Transparent)
         {
             if (BackGradientSettingsDisabled.UseDefaultGradientSpan)
             {
                 return(CoolGradient.GetDefaultGradientSpan(BackGradientSettingsDisabled.GradientType));
             }
             else
             {
                 return(BackGradientSettingsDisabled.GradientSpan);
             }
         }
         if (m_blMouseDown && BackGradientSettingsMouseDown.GradientColor1 != Color.Transparent)
         {
             if (BackGradientSettingsMouseDown.UseDefaultGradientSpan)
             {
                 return(CoolGradient.GetDefaultGradientSpan(BackGradientSettingsMouseDown.GradientType));
             }
             else
             {
                 return(BackGradientSettingsMouseDown.GradientSpan);
             }
         }
         else if (m_blMouseOver && BackGradientSettingsMouseOver.GradientColor1 != Color.Transparent)
         {
             if (BackGradientSettingsMouseOver.UseDefaultGradientSpan)
             {
                 return(CoolGradient.GetDefaultGradientSpan(BackGradientSettingsMouseOver.GradientType));
             }
             else
             {
                 return(BackGradientSettingsMouseOver.GradientSpan);
             }
         }
         else
         {
             if (BackGradientSettings.UseDefaultGradientSpan)
             {
                 return(CoolGradient.GetDefaultGradientSpan(BackGradientSettings.GradientType));
             }
             else
             {
                 return(BackGradientSettings.GradientSpan);
             }
         }//end if
     }
     catch (Exception err)
     {
         ErrorHandler.ShowErrorMessage(err, "Error in GetBackGradientSpan function of DotCoolPanel control.");
         return(0f);
     }
 }
Пример #3
0
        /// <summary>
        /// Gets the appropriate gradient span value of the check symbol based on the control's current state.
        /// </summary>
        /// <returns></returns>
        /// <param name="delStateCheckFunc">Delegate to a function containing additional logic to add to the function.  The function will be usually
        /// passed from children classes to the base DotCoolControl class to embed additional criteria to a visual setting state checking function.</param>
        /// <returns></returns>
        protected virtual float GetCheckGradientSpan(Func <float> delStateCheckFunc)
        {
            try
            {
                if (!this.Enabled && CheckGradientSettings.GradientColor1 != Color.Transparent)
                {
                    if (CheckGradientSettingsDisabled.UseDefaultGradientSpan)
                    {
                        return(CoolGradient.GetDefaultGradientSpan(CheckGradientSettingsDisabled.GradientType));
                    }
                    else
                    {
                        return(CheckGradientSettingsDisabled.GradientSpan);
                    }
                }
                else if (m_blMouseOver && CheckGradientSettingsMouseOver.GradientColor1 != Color.Transparent)
                {
                    if (CheckGradientSettingsMouseOver.UseDefaultGradientSpan)
                    {
                        return(CoolGradient.GetDefaultGradientSpan(CheckGradientSettingsMouseOver.GradientType));
                    }
                    else
                    {
                        return(CheckGradientSettingsMouseOver.GradientSpan);
                    }
                }
                else if (delStateCheckFunc != null)
                {
                    float fResult = delStateCheckFunc.Invoke();

                    if (fResult != -1)
                    {
                        return(fResult);
                    }
                }

                if (CheckGradientSettings.UseDefaultGradientSpan)
                {
                    return(CoolGradient.GetDefaultGradientSpan(CheckGradientSettings.GradientType));
                }
                else
                {
                    return(CheckGradientSettings.GradientSpan);
                }
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in GetCheckGradientSpan function of DotCoolCheckBase control.");
                return(0f);
            }
        }