Example #1
0
        public static bool Fill(Graphics gr, Rectangle dstrc, Rectangle srcrc, GradientColor gradientColor)
        {
            Color startColor = gradientColor.StartColor;
            Color endColor   = gradientColor.EndColor;

            if (gradientColor.FillDirection == FillDirection.Horizontal)
            {
                if ((dstrc.X != srcrc.X) || (dstrc.Width != srcrc.Width))
                {
                    float num  = ((float)(dstrc.Left - srcrc.X)) / ((float)srcrc.Width);
                    float num2 = ((float)(dstrc.Right - srcrc.X)) / ((float)srcrc.Width);
                    int   num3 = endColor.R - startColor.R;
                    int   num4 = endColor.G - startColor.G;
                    int   num5 = endColor.B - startColor.B;
                    startColor = Color.FromArgb((byte)(gradientColor.StartColor.R + (num3 * num)), (byte)(gradientColor.StartColor.G + (num4 * num)), (byte)(gradientColor.StartColor.B + (num5 * num)));
                    endColor   = Color.FromArgb((byte)(gradientColor.StartColor.R + (num3 * num2)), (byte)(gradientColor.StartColor.G + (num4 * num2)), (byte)(gradientColor.StartColor.B + (num5 * num2)));
                }
            }
            else if ((dstrc.Y != srcrc.Y) || (dstrc.Height != srcrc.Height))
            {
                float num6  = ((float)(dstrc.Top - srcrc.Y)) / ((float)srcrc.Height);
                float num7  = ((float)(dstrc.Bottom - srcrc.Y)) / ((float)srcrc.Height);
                int   num8  = endColor.R - startColor.R;
                int   num9  = endColor.G - startColor.G;
                int   num10 = endColor.B - startColor.B;
                startColor = Color.FromArgb((byte)(gradientColor.StartColor.R + (num8 * num6)), (byte)(gradientColor.StartColor.G + (num9 * num6)), (byte)(gradientColor.StartColor.B + (num10 * num6)));
                endColor   = Color.FromArgb((byte)(gradientColor.StartColor.R + (num8 * num7)), (byte)(gradientColor.StartColor.G + (num9 * num7)), (byte)(gradientColor.StartColor.B + (num10 * num7)));
            }
            if (Environment.OSVersion.Platform != PlatformID.WinCE)
            {
                return(FillManaged(gr, dstrc, startColor, endColor, gradientColor.FillDirection));
            }
            Win32Helper.TRIVERTEX[]     pVertex = new Win32Helper.TRIVERTEX[] { new Win32Helper.TRIVERTEX(dstrc.X, dstrc.Y, startColor), new Win32Helper.TRIVERTEX(dstrc.Right, dstrc.Bottom, endColor) };
            Win32Helper.GRADIENT_RECT[] pMesh   = new Win32Helper.GRADIENT_RECT[] { new Win32Helper.GRADIENT_RECT(0, 1) };
            IntPtr hdc  = gr.GetHdc();
            bool   flag = false;

            try
            {
                flag = Win32Helper.GradientFill(hdc, pVertex, (uint)pVertex.Length, pMesh, (uint)pMesh.Length, (uint)gradientColor.FillDirection);
                gr.ReleaseHdc(hdc);
            }
            catch (Exception)
            {
                gr.ReleaseHdc(hdc);
                flag = FillManaged(gr, dstrc, startColor, endColor, gradientColor.FillDirection);
            }
            return(flag);
        }
Example #2
0
 public static bool Fill(Graphics gr, Rectangle dstrc, Rectangle srcrc, GradientColor gradientColor)
 {
     Color startColor = gradientColor.StartColor;
     Color endColor = gradientColor.EndColor;
     if (gradientColor.FillDirection == FillDirection.Horizontal)
     {
         if ((dstrc.X != srcrc.X) || (dstrc.Width != srcrc.Width))
         {
             float num = ((float) (dstrc.Left - srcrc.X)) / ((float) srcrc.Width);
             float num2 = ((float) (dstrc.Right - srcrc.X)) / ((float) srcrc.Width);
             int num3 = endColor.R - startColor.R;
             int num4 = endColor.G - startColor.G;
             int num5 = endColor.B - startColor.B;
             startColor = Color.FromArgb((byte) (gradientColor.StartColor.R + (num3 * num)), (byte) (gradientColor.StartColor.G + (num4 * num)), (byte) (gradientColor.StartColor.B + (num5 * num)));
             endColor = Color.FromArgb((byte) (gradientColor.StartColor.R + (num3 * num2)), (byte) (gradientColor.StartColor.G + (num4 * num2)), (byte) (gradientColor.StartColor.B + (num5 * num2)));
         }
     }
     else if ((dstrc.Y != srcrc.Y) || (dstrc.Height != srcrc.Height))
     {
         float num6 = ((float) (dstrc.Top - srcrc.Y)) / ((float) srcrc.Height);
         float num7 = ((float) (dstrc.Bottom - srcrc.Y)) / ((float) srcrc.Height);
         int num8 = endColor.R - startColor.R;
         int num9 = endColor.G - startColor.G;
         int num10 = endColor.B - startColor.B;
         startColor = Color.FromArgb((byte) (gradientColor.StartColor.R + (num8 * num6)), (byte) (gradientColor.StartColor.G + (num9 * num6)), (byte) (gradientColor.StartColor.B + (num10 * num6)));
         endColor = Color.FromArgb((byte) (gradientColor.StartColor.R + (num8 * num7)), (byte) (gradientColor.StartColor.G + (num9 * num7)), (byte) (gradientColor.StartColor.B + (num10 * num7)));
     }
     if (Environment.OSVersion.Platform != PlatformID.WinCE)
     {
         return FillManaged(gr, dstrc, startColor, endColor, gradientColor.FillDirection);
     }
     Win32Helper.TRIVERTEX[] pVertex = new Win32Helper.TRIVERTEX[] { new Win32Helper.TRIVERTEX(dstrc.X, dstrc.Y, startColor), new Win32Helper.TRIVERTEX(dstrc.Right, dstrc.Bottom, endColor) };
     Win32Helper.GRADIENT_RECT[] pMesh = new Win32Helper.GRADIENT_RECT[] { new Win32Helper.GRADIENT_RECT(0, 1) };
     IntPtr hdc = gr.GetHdc();
     bool flag = false;
     try
     {
         flag = Win32Helper.GradientFill(hdc, pVertex, (uint) pVertex.Length, pMesh, (uint) pMesh.Length, (uint) gradientColor.FillDirection);
         gr.ReleaseHdc(hdc);
     }
     catch (Exception)
     {
         gr.ReleaseHdc(hdc);
         flag = FillManaged(gr, dstrc, startColor, endColor, gradientColor.FillDirection);
     }
     return flag;
 }