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

Pretty Buttons for PocketPC

0.00/5 (No votes)
29 Nov 2006 1  
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 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