Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

GradientFill (gdi32)
 
.
Summary
Performs GDI32 based gradient fills of rectangles and triangles

C# Signature:

  [DllImport("gdi32.dll", EntryPoint="GdiGradientFill", ExactSpelling = true)]
  public static extern bool GradientFill(
    IntPtr hdc,           // handle to DC
    TRIVERTEX[] pVertex,    // array of vertices
    uint dwNumVertex,     // number of vertices
    GRADIENT_RECT[] pMesh,           // array of gradients
    uint dwNumMesh,       // size of gradient array
    uint dwMode           // gradient fill mode);

  [DllImport("gdi32.dll", EntryPoint="GdiGradientFill", ExactSpelling = true)]
  public static extern bool GradientFill(
    IntPtr hdc,           // handle to DC
    TRIVERTEX[] pVertex,    // array of vertices
    uint dwNumVertex,     // number of vertices
    GRADIENT_TRIANGE[] pMesh,           // array of gradients
    uint dwNumMesh,       // size of gradient array
    uint dwMode           // gradient fill mode);

VB Signature:

Declare Function GradientFill Lib "gdi32.dll" (TODO) As TODO

User-Defined Types:

GRADIENT_RECT

GRADIENT_TRIANGLE

TRIVERTEX

The dwMode is one of the constants from GRADIENT_.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

The GDI32.dll does not contain a GradientFill() function. The actual entry point is GdiGradientFill(). That's why the 'EntryPoint' attribute is present.

This method creates one entry each for rectangles and triangles. It's just a matter of convenience and error checking by the compiler.

Tips & Tricks:

Please add some!

Sample Code:

public class Gradient
{
    public const uint
      GRADIENT_FILL_RECT_H = 0x00000000,
      GRADIENT_FILL_RECT_V = 0x00000001,
      GRADIENT_FILL_TRIANGLE = 0x00000002,
      GRADIENT_FILL_OP_FLAG = 0x000000ff;

    [DllImport("gdi32.dll", EntryPoint="GdiGradientFill", ExactSpelling = true)]
    public static extern bool GradientFill(
      IntPtr hdc,           // handle to DC
      TRIVERTEX[] pVertex,    // array of vertices
      uint dwNumVertex,     // number of vertices
      GRADIENT_RECT[] pMesh,           // array of gradients
      uint dwNumMesh,       // size of gradient array
      uint dwMode           // gradient fill mode
    );

    public static void  DrawNiceRectangle(hDC graphPort, Rectangle Frame)
    {
      // Draw from whitish blue at the top, to a light blue at the bottom
      TRIVERTEX[] vert = new TRIVERTEX[]{
        new TRIVERTEX(Frame.Left,Frame.Top,0xff00,0xff00,0xffff,0x0),
        new TRIVERTEX(Frame.Right,Frame.Bottom,0x0000,0x0000,0xff00,0x0)};

      GRADIENT_RECT[] gRect = new GRADIENT_RECT[]{
        new GRADIENT_RECT(0,1)};

      Gradient.GradientFill(graphPort, vert, 2, gRect, 1, Gradient.GRADIENT_FILL_RECT_V);
}

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions