Click here to Skip to main content
13,249,087 members (39,674 online)
Click here to Skip to main content
Add your own
alternative version


27 bookmarked
Posted 5 Jul 2008

A Gradient Button for Windows Mobile

, 5 Jul 2008
Rate this:
Please Sign up or sign in to vote.
A gradient button for Windows Mobile and the .NET Compact Framework.


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:

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,
uint dwNumMesh,
uint dwMode);

The above method is the key for gradients in Windows. Visti this link for more info:


  • First version: 05/07/2008.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Team Leader
Singapore Singapore
- B.Sc. degree in Computer Science.
- 4+ years experience in Visual and
- Obsessed in OOP style design and programming.
- Designing and developing Network security tools.
- Designing and developing a client/server application for sharing files among users in a way other than FTP protocol.
- Designing and implementing GSM gateway applications and bulk messaging.
- Windows Mobile and Symbian Programming
- Having knowledge with ERP solutions

The summary of my skills:
C#, VB.Net#,, VC++, Java, WPF,WCF, Oracle, SQL Server, MS Access, Windows NT administration


You may also be interested in...


Comments and Discussions

General"How Do I?" Videos for Devices Pin
Yves4-Aug-10 5:09
memberYves4-Aug-10 5:09 
QuestionHow to apply a image to a button 2008 SmartDevice Applications Pin
Chanuri8-Jan-09 1:27
memberChanuri8-Jan-09 1:27 
AnswerRe: How to apply a image to a button 2008 SmartDevice Applications Pin
Dr.Luiji8-Jan-09 4:36
memberDr.Luiji8-Jan-09 4:36 
GeneralThanks Pin
Joel Ivory Johnson2-Sep-08 13:26
memberJoel Ivory Johnson2-Sep-08 13:26 
GeneralRe: Thanks Pin
Ravenet10-Sep-08 17:36
memberRavenet10-Sep-08 17:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171114.1 | Last Updated 5 Jul 2008
Article Copyright 2008 by Ravenet
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid