コード例 #1
0
ファイル: GradientFill.cs プロジェクト: north0808/haina
 public static bool Fill(Graphics gr, Rectangle rc, Color startColor, Color middleColor1, Color middleColor2, Color endColor, int middleColor1Offset, int middleColor2Offset, FillDirection fillDirection)
 {
     bool flag = (middleColor1 != Color.Transparent) | (middleColor2 != Color.Transparent);
     if (Environment.OSVersion.Platform != PlatformID.WinCE)
     {
         return FillManagedWithMiddle(gr, rc, startColor, middleColor1, middleColor2, endColor, middleColor1Offset, middleColor2Offset, fillDirection);
     }
     int num = 2;
     if (flag)
     {
         if (middleColor1 == Color.Transparent)
         {
             middleColor1 = middleColor2;
             middleColor1Offset = middleColor2Offset;
         }
         if (middleColor2 == Color.Transparent)
         {
             middleColor2 = middleColor1;
             middleColor2Offset = middleColor1Offset;
         }
         if (middleColor1Offset == middleColor2Offset)
         {
             num += 2;
         }
         else
         {
             num += 4;
         }
     }
     Win32Helper.TRIVERTEX[] pVertex = new Win32Helper.TRIVERTEX[num];
     int index = 0;
     pVertex[index++] = new Win32Helper.TRIVERTEX(rc.X, rc.Y, startColor);
     if (flag)
     {
         if (fillDirection == FillDirection.Horizontal)
         {
             int num3 = (rc.Width * middleColor1Offset) / 100;
             int num4 = (rc.Width * middleColor2Offset) / 100;
             pVertex[index++] = new Win32Helper.TRIVERTEX(rc.X + num3, rc.Bottom, middleColor1);
             if (middleColor1Offset != middleColor2Offset)
             {
                 pVertex[index++] = new Win32Helper.TRIVERTEX(rc.X + num3, rc.Y, middleColor1);
                 pVertex[index++] = new Win32Helper.TRIVERTEX(rc.X + num4, rc.Bottom, middleColor2);
             }
             pVertex[index++] = new Win32Helper.TRIVERTEX(rc.X + num4, rc.Y, middleColor2);
         }
         else
         {
             int num5 = (rc.Height * middleColor1Offset) / 100;
             int num6 = (rc.Height * middleColor2Offset) / 100;
             pVertex[index++] = new Win32Helper.TRIVERTEX(rc.Right, rc.Y + num5, middleColor1);
             if (middleColor1Offset != middleColor2Offset)
             {
                 pVertex[index++] = new Win32Helper.TRIVERTEX(rc.X, rc.Y + num5, middleColor1);
                 pVertex[index++] = new Win32Helper.TRIVERTEX(rc.Right, rc.Y + num6, middleColor2);
             }
             pVertex[index++] = new Win32Helper.TRIVERTEX(rc.X, rc.Y + num6, middleColor2);
         }
     }
     pVertex[index] = new Win32Helper.TRIVERTEX(rc.Right, rc.Bottom, endColor);
     Win32Helper.GRADIENT_RECT[] pMesh = null;
     if (flag)
     {
         if (middleColor1Offset != middleColor2Offset)
         {
             pMesh = new Win32Helper.GRADIENT_RECT[] { new Win32Helper.GRADIENT_RECT(0, 1), new Win32Helper.GRADIENT_RECT(2, 3), new Win32Helper.GRADIENT_RECT(4, 5) };
         }
         else
         {
             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);
         FillManagedWithMiddle(gr, rc, startColor, middleColor1, middleColor2, endColor, middleColor1Offset, middleColor2Offset, fillDirection);
         flag2 = true;
     }
     return flag2;
 }
コード例 #2
0
ファイル: GradientFill.cs プロジェクト: windygu/haina
        public static bool Fill(Graphics gr, Rectangle rc, Color startColor, Color middleColor1, Color middleColor2, Color endColor, int middleColor1Offset, int middleColor2Offset, FillDirection fillDirection)
        {
            bool flag = (middleColor1 != Color.Transparent) | (middleColor2 != Color.Transparent);

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

            if (flag)
            {
                if (middleColor1 == Color.Transparent)
                {
                    middleColor1       = middleColor2;
                    middleColor1Offset = middleColor2Offset;
                }
                if (middleColor2 == Color.Transparent)
                {
                    middleColor2       = middleColor1;
                    middleColor2Offset = middleColor1Offset;
                }
                if (middleColor1Offset == middleColor2Offset)
                {
                    num += 2;
                }
                else
                {
                    num += 4;
                }
            }
            Win32Helper.TRIVERTEX[] pVertex = new Win32Helper.TRIVERTEX[num];
            int index = 0;

            pVertex[index++] = new Win32Helper.TRIVERTEX(rc.X, rc.Y, startColor);
            if (flag)
            {
                if (fillDirection == FillDirection.Horizontal)
                {
                    int num3 = (rc.Width * middleColor1Offset) / 100;
                    int num4 = (rc.Width * middleColor2Offset) / 100;
                    pVertex[index++] = new Win32Helper.TRIVERTEX(rc.X + num3, rc.Bottom, middleColor1);
                    if (middleColor1Offset != middleColor2Offset)
                    {
                        pVertex[index++] = new Win32Helper.TRIVERTEX(rc.X + num3, rc.Y, middleColor1);
                        pVertex[index++] = new Win32Helper.TRIVERTEX(rc.X + num4, rc.Bottom, middleColor2);
                    }
                    pVertex[index++] = new Win32Helper.TRIVERTEX(rc.X + num4, rc.Y, middleColor2);
                }
                else
                {
                    int num5 = (rc.Height * middleColor1Offset) / 100;
                    int num6 = (rc.Height * middleColor2Offset) / 100;
                    pVertex[index++] = new Win32Helper.TRIVERTEX(rc.Right, rc.Y + num5, middleColor1);
                    if (middleColor1Offset != middleColor2Offset)
                    {
                        pVertex[index++] = new Win32Helper.TRIVERTEX(rc.X, rc.Y + num5, middleColor1);
                        pVertex[index++] = new Win32Helper.TRIVERTEX(rc.Right, rc.Y + num6, middleColor2);
                    }
                    pVertex[index++] = new Win32Helper.TRIVERTEX(rc.X, rc.Y + num6, middleColor2);
                }
            }
            pVertex[index] = new Win32Helper.TRIVERTEX(rc.Right, rc.Bottom, endColor);
            Win32Helper.GRADIENT_RECT[] pMesh = null;
            if (flag)
            {
                if (middleColor1Offset != middleColor2Offset)
                {
                    pMesh = new Win32Helper.GRADIENT_RECT[] { new Win32Helper.GRADIENT_RECT(0, 1), new Win32Helper.GRADIENT_RECT(2, 3), new Win32Helper.GRADIENT_RECT(4, 5) };
                }
                else
                {
                    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);
                FillManagedWithMiddle(gr, rc, startColor, middleColor1, middleColor2, endColor, middleColor1Offset, middleColor2Offset, fillDirection);
                flag2 = true;
            }
            return(flag2);
        }