Click here to Skip to main content
Click here to Skip to main content

Pretty Buttons for PocketPC

, 29 Nov 2006
Rate this:
Please Sign up or sign in to vote.
A 3D-gradient looking button for PocketPC, using only the .NET Compact Framework.

Introduction

I had all kinds of trouble finding a pre-built rounded Button class for Pocket PC using the Compact Framework because Graphics has no DrawArc or similar methods to support doing this quickly. My control displays in light blue (when Enabled = True) or gray (when Enabled=False).

What the button looks like when enabled with my default light-blue gradient.

Background

There is a lot of stuff out there on how to do this with GDI or Java, but I didn't want to import unnecessary libraries or go through the headache of dealing with API calls in an already complex application. I wanted to use the same Drawing.Graphics object that the controls were already using. I tried to modify the code from several sources, but to no avail; there was always a call to something that wasn't in the .NET Compact Framework. Finally, I created a custom control using the Graphics FillPolygon method and it worked like a charm. This was a little bit of a learning experience for me though, I must say, as it was the first time I've ever had to work with manually drawing polygons for any reason.

Using it

To use this code, simply add the existing control to your project. If you want to change stuff like the color of the background (shown only in the corners), you will need to modify the code (unless you love Color.SteelBlue as much as I do). Also, by replacing the current gradients in the imagelist, you can change the display colors which are selected during runtime, by using imagelist1.images(0) as the "Enabled=True" gradient, and imagelist.images(1) for the gradient to be used when Enabled is set to False. Also, if you want to be able to view the Text property at design time, it must be set at design-time in the [Designer]'s under-the-hood code.

'Example From FrmStart.Designer.vb
'btnXit
Me.btnXit.Location = New System.Drawing.Point(3, 157)
Me.btnXit.Name = "btnXit"
Me.btnXit.Size = New System.Drawing.Size(216, 16)
Me.btnXit.TabIndex = 0
Me.btnXit.Text = "Exit"

Points of Interest

  • Even with the massively cut-down graphics routines in the Compact Framework, we can still deliver visually pleasing controls; albeit with a little extra effort.
  • The current default size of the control is set to 216 by 16 as this seems to nicely fill out the width requirements for my PDA.
  • I've only tested this on the Compaq IPAQ and .NET's emulator for PocketPC2002. If you find any problems with it, fix them! My code is posted as is, so hopefully, you will have to change it and make it your own during usage.

History

  • Posted on Nov. 29, 2006.

License

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

Share

About the Author

SoulFurnace

Canada Canada
No Biography provided

Comments and Discussions

 
Questionclickable? Pinmembermad_cow119-Dec-06 16:13 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140821.2 | Last Updated 29 Nov 2006
Article Copyright 2006 by SoulFurnace
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid