Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

A Gradient Button for Windows Mobile

0.00/5 (No votes)
5 Jul 2008 1  
A gradient button for Windows Mobile and the .NET Compact Framework.

Introduction

This is a gradient button for use in Windows Mobile. I had to create a gradient button for use in Windows Mobile with Managed code.

Using the code

I have created the gradient button control by inheriting from Control. Another class I use is the gradient color maker from unmanaged code. For this, I use the "TRIVERTEX" struct. You can get more info about it from: http://msdn.microsoft.com/en-us/library/ms532283(VS.85).aspx.

public struct TRIVERTEX
{
    public int x;
    public int y;
    public ushort Red;
    public ushort Green;
    public ushort Blue;
    public ushort Alpha;
    public TRIVERTEX(int x, int y, Color color)
        : this(x, y, color.R, color.G, color.B, color.A)
    {
    }
    public TRIVERTEX(
        int x, int y,
        ushort red, ushort green, ushort blue,
        ushort alpha)
    {
        this.x = x;
        this.y = y;
        this.Red = (ushort)(red << 8);
        this.Green = (ushort)(green << 8);
        this.Blue = (ushort)(blue << 8);
        this.Alpha = (ushort)(alpha << 8);
    }
}
public struct GRADIENT_RECT
{
    public uint UpperLeft;
    public uint LowerRight;
    public GRADIENT_RECT(uint ul, uint lr)
    {
        this.UpperLeft = ul;
        this.LowerRight = lr;
    }
}

I have also used an unmanaged function for making gradient colors for drawing the button:

[DllImport("coredll.dll", SetLastError = true, EntryPoint = "GradientFill")]
public extern static bool GradientFill(
IntPtr hdc,
TRIVERTEX[] pVertex,
uint dwNumVertex,
GRADIENT_RECT[] pMesh,
uint dwNumMesh,
uint dwMode);

The above method is the key for gradients in Windows. Visti this link for more info: http://msdn.microsoft.com/en-us/library/ms229655(VS.80).aspx.

History

  • First version: 05/07/2008.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here