Ejemplo n.º 1
0
        // This method wraps the PInvoke to GradientFill.
        // Parmeters:
        //  gr - The Graphics object we are filling
        //  rc - The rectangle to fill
        //  startColor - The starting color for the fill
        //  endColor - The ending color for the fill
        //  fillDir - The direction to fill
        //
        // Returns true if the call to GradientFill succeeded; false
        // otherwise.
        public static bool Fill(
            Graphics gr,
            Rectangle rc,
            Color startColor, Color endColor,
            FillDirection fillDir)
        {
            // Initialize the data to be used in the call to GradientFill.
            Win32Helper.TRIVERTEX[] tva = new Win32Helper.TRIVERTEX[2];
            tva[0] = new Win32Helper.TRIVERTEX(rc.X, rc.Y, startColor);
            tva[1] = new Win32Helper.TRIVERTEX(rc.Right, rc.Bottom, endColor);
            Win32Helper.GRADIENT_RECT[] gra = new Win32Helper.GRADIENT_RECT[] {
            new Win32Helper.GRADIENT_RECT(0, 1)};

            // Get the hDC from the Graphics object.
            IntPtr hdc = gr.GetHdc();

            // PInvoke to GradientFill.
            bool b;

            b = Win32Helper.GradientFill(
                    hdc,
                    tva,
                    (uint)tva.Length,
                    gra,
                    (uint)gra.Length,
                    (uint)fillDir);
            System.Diagnostics.Debug.Assert(b, string.Format(
                "GradientFill failed: {0}",
                System.Runtime.InteropServices.Marshal.GetLastWin32Error()));

            // Release the hDC from the Graphics object.
            gr.ReleaseHdc(hdc);

            return b;
        }
Ejemplo n.º 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;
 }