Windows Mobile 的渐变按钮
适用于 Windows Mobile 和 .NET Compact Framework 的渐变按钮。
引言
这是一个用于 Windows Mobile 的渐变按钮。我需要为 Windows Mobile 创建一个使用托管代码的渐变按钮。
使用代码
我通过继承自 Control
创建了这个渐变按钮控件。我使用的另一个类是从非托管代码中获取的渐变颜色生成器。为此,我使用了 "TRIVERTEX
" 结构。您可以在以下网址获取更多信息: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;
}
}
我还使用了一个非托管函数来创建用于绘制按钮的渐变颜色
[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);
上述方法是 Windows 中渐变的关键。访问此链接以获取更多信息:http://msdn.microsoft.com/en-us/library/ms229655(VS.80).aspx。
历史
- 第一个版本:2008/07/05。