Пример #1
0
 public static bool Fill(Graphics gr, Rectangle rc, Color startColor, Color middleColor1, Color middleColor2, Color endColor, FillDirection fillDirection)
 {
     bool flag = (middleColor1 != Color.Transparent) | (middleColor2 != Color.Transparent);
     if (Environment.OSVersion.Platform != PlatformID.WinCE)
     {
         return FillManagedWithMiddle(gr, rc, startColor, middleColor1, middleColor2, endColor, fillDirection);
     }
     int num = 2;
     if (flag)
     {
         num += 2;
     }
     Win32Helper.TRIVERTEX[] pVertex = new Win32Helper.TRIVERTEX[num];
     pVertex[0] = new Win32Helper.TRIVERTEX(rc.X, rc.Y, startColor);
     if (flag)
     {
         if (middleColor1 == Color.Transparent)
         {
             middleColor1 = middleColor2;
         }
         if (middleColor2 == Color.Transparent)
         {
             middleColor2 = middleColor1;
         }
         if (fillDirection == FillDirection.Horizontal)
         {
             pVertex[1] = new Win32Helper.TRIVERTEX(rc.X + (rc.Width / 2), rc.Bottom, middleColor1);
             pVertex[2] = new Win32Helper.TRIVERTEX(rc.X + (rc.Width / 2), rc.Y, middleColor2);
         }
         else
         {
             pVertex[1] = new Win32Helper.TRIVERTEX(rc.Right, rc.Y + (rc.Height / 2), middleColor1);
             pVertex[2] = new Win32Helper.TRIVERTEX(rc.X, rc.Y + (rc.Height / 2), middleColor2);
         }
     }
     pVertex[num - 1] = new Win32Helper.TRIVERTEX(rc.Right, rc.Bottom, endColor);
     Win32Helper.GRADIENT_RECT[] pMesh = null;
     if (flag)
     {
         pMesh = new Win32Helper.GRADIENT_RECT[] { new Win32Helper.GRADIENT_RECT(0, 1), new Win32Helper.GRADIENT_RECT(2, 3) };
     }
     else
     {
         pMesh = new Win32Helper.GRADIENT_RECT[] { new Win32Helper.GRADIENT_RECT(0, 1) };
     }
     IntPtr hdc = gr.GetHdc();
     bool flag2 = false;
     try
     {
         flag2 = Win32Helper.GradientFill(hdc, pVertex, (uint) pVertex.Length, pMesh, (uint) pMesh.Length, (uint) fillDirection);
         gr.ReleaseHdc(hdc);
     }
     catch (Exception)
     {
         gr.ReleaseHdc(hdc);
         flag2 = FillManagedWithMiddle(gr, rc, startColor, middleColor1, middleColor2, endColor, fillDirection);
     }
     return flag2;
 }
Пример #2
0
        public static bool Fill(Graphics gr, Rectangle rc, Color startColor, Color middleColor1, Color middleColor2, Color endColor, FillDirection fillDirection)
        {
            bool flag = (middleColor1 != Color.Transparent) | (middleColor2 != Color.Transparent);

            if (Environment.OSVersion.Platform != PlatformID.WinCE)
            {
                return(FillManagedWithMiddle(gr, rc, startColor, middleColor1, middleColor2, endColor, fillDirection));
            }
            int num = 2;

            if (flag)
            {
                num += 2;
            }
            Win32Helper.TRIVERTEX[] pVertex = new Win32Helper.TRIVERTEX[num];
            pVertex[0] = new Win32Helper.TRIVERTEX(rc.X, rc.Y, startColor);
            if (flag)
            {
                if (middleColor1 == Color.Transparent)
                {
                    middleColor1 = middleColor2;
                }
                if (middleColor2 == Color.Transparent)
                {
                    middleColor2 = middleColor1;
                }
                if (fillDirection == FillDirection.Horizontal)
                {
                    pVertex[1] = new Win32Helper.TRIVERTEX(rc.X + (rc.Width / 2), rc.Bottom, middleColor1);
                    pVertex[2] = new Win32Helper.TRIVERTEX(rc.X + (rc.Width / 2), rc.Y, middleColor2);
                }
                else
                {
                    pVertex[1] = new Win32Helper.TRIVERTEX(rc.Right, rc.Y + (rc.Height / 2), middleColor1);
                    pVertex[2] = new Win32Helper.TRIVERTEX(rc.X, rc.Y + (rc.Height / 2), middleColor2);
                }
            }
            pVertex[num - 1] = new Win32Helper.TRIVERTEX(rc.Right, rc.Bottom, endColor);
            Win32Helper.GRADIENT_RECT[] pMesh = null;
            if (flag)
            {
                pMesh = new Win32Helper.GRADIENT_RECT[] { new Win32Helper.GRADIENT_RECT(0, 1), new Win32Helper.GRADIENT_RECT(2, 3) };
            }
            else
            {
                pMesh = new Win32Helper.GRADIENT_RECT[] { new Win32Helper.GRADIENT_RECT(0, 1) };
            }
            IntPtr hdc   = gr.GetHdc();
            bool   flag2 = false;

            try
            {
                flag2 = Win32Helper.GradientFill(hdc, pVertex, (uint)pVertex.Length, pMesh, (uint)pMesh.Length, (uint)fillDirection);
                gr.ReleaseHdc(hdc);
            }
            catch (Exception)
            {
                gr.ReleaseHdc(hdc);
                flag2 = FillManagedWithMiddle(gr, rc, startColor, middleColor1, middleColor2, endColor, fillDirection);
            }
            return(flag2);
        }