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
True) or gray (when
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.
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 "
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.
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.