Hawaiʻi's Technology Community

Paint Delegates in Java Swing and .NET WinForms

A few months back I blogged about an excellent Swing look and feel called
Nimbus. Nimbus is entirely vector based and does all its painting using delegates that can be layered and shared. Painters are used to draw tiled images, gradients, stripes, glass effects, etc. They also support Photoshop-like filters. Painter Example:

    MattePainter matte = new MattePainter(new Color(21, 21, 71));
PinstripePainter stripes = new PinstripePainter();
stripes.setPaint(new Color(255, 255, 255, 15));
GlossPainter gloss = new GlossPainter();

TextPainter text = new TextPainter();
text.setFont(new Font("Informal Roman", Font.BOLD, 36));
text.setPaint(new Color(255,255,230));
text.setLocation(new Point2D.Double(0.5, 0.5));
If you want to take Painters for a spin pull down SwingX from SwingLabs. For more info on Nimbus check out
Jasper Pott's blog.
Paint Delegates in WinForms We have worked on a number of WinForms projects that required similar functionality. Unfortunately the standard widgets such as System.Windows.Forms.Button don't support any kind of custom backgrounds or borders. To remedy this I decided to bring the idea of Painters to WinForms. I created a minimal implementation of Painters and a few basic widgets that support custom painting. The painters support gradients, striping, tiled images and custom borders. Painters have a large number of properties which gives us the perfect opportunity to show off C# 3.0's object initializers:

    var lightBorderColor = Color.FromArgb(102, 102, 200);
var darkBorderColor = Color.FromArgb(60, 60, 255);

button.Painter = new Painter {
GradientFill = new GradientFill {
ColorA = Color.FromArgb(192, 192, 255),
ColorB = Color.Navy
MultiBorder = new MultiBorder {
OuterBorderSize = new Padding(1),
TopOuterColor = lightBorderColor,
LeftOuterColor = lightBorderColor,
BottomOuterColor = darkBorderColor,
RightOuterColor = darkBorderColor
ForeColor = Color.FromArgb(255, 255, 230)
I also included support for manipulation of painters in the designer. For multi-state widgets like buttons a painter is provided for each state (ex. normal, pressed and hover.) Examples of widgets skinned with this library are pictured below. The source and binaries are attached. This project requires Visual C# or VisualStudio 2008. The library has no dependencies.

TODOs: - Add a glass effect - Add a shadow effect - Add support for autosizing of labels (currently the autosizing doesn't work because of antialiasing ) Let me know if you have any questions or comments.
Ikayzo - Design • Build • Localize | Web • Desktop • Mobile

Views: 611


You need to be a member of TechHui to add comments!

Join TechHui


web design, web development, localization

© 2024   Created by Daniel Leuck.   Powered by

Badges  |  Report an Issue  |  Terms of Service