Archive for April, 2006

Until now the toolkit has been using a small custom engine for drawing text. Not any more, it’s time to shift over to the TextRenderer class.

In an ideal world I would like to use GDI+ to draw text because it offers the ability to draw using a Brush which allows some really nice effects. You can use gradient fills or even overlay an image to get just the right subtle texture. Unfortunately we all know that the GDI+ versions of MeasureString and DrawString are useless. They are just not reliable in getting an accurate measure of the text size. Well I suppose they are reliable in that they always give you an answer way bigger than the actual text size. But as I need to get pretty close to pixel perfect measuring they will not suffice.

So instead I created a little engine that draws the text one character at a time and does some rather slow jiggery pockery to get the pixel exact size of the text that is being drawn. Up to a point it did work and so it has been there right from the start of the toolkit. But it does not handle complex scripts very well and even simple English text does not appear exactly the same way it would on other windows controls. So it is time to ditch the custom engine and make the switch to the .NET2 provided TextRenderer class.

There are however a couple of drawbacks to using the TextRenderer class. First of all it only draws text using a single color. No more gradient, radial or image effects. This is a shame but not a big a deal as it is not the most used feature of the toolkit. Second is that it cannot be used to draw at an angle.

Now you can get around the second issue by drawing onto a bitmap first and then blitting the bitmap onto the screen using a rotate transform to get the required angle. Unfortunately there is yet another limitation because when you draw onto a bitmap it will not use transparency. Why it cannot do this is a complete mystery to me but it cannot.

So the next version of the toolkit will be using the TextRenderer and so draw in any language and complex script that you care to use in your application. But you need to be careful in choosing your font if you need controls that are orientated vertically as they will ignore the anti aliasing.

In trying to make the KryptonSplitContainer as efficient as possible I left just enough room for a bug to appear. If you add a child control to one of the panels with anchoring on the right or bottom them it goes horribly wrong.

I added the ISupportInitialize interface to the control so that I would be notified at the start and end of control initialization with calls to the BeginInit and EndInit methods. During the time between these two calls I was not repositioning or resizing the two splitter panels. Instead only when the EndInit occurs would I perform a layout cycle.

This is because the designer generated code might be making several calls to properties that would require a layout of the control. So if the SplitterWidth, Panel1MinSize and Panel2MinSize were all modified then it would cause the splitter to layout three times. So I thought I was being efficient by avoiding all the extra layouts that were taking place.

But this is where it all goes wrong for child controls. Child controls of the two panels are added after the BeginInit call but before the main splitter control properties are modified by the designer generated code. So if the child control is anchored to the right or bottom then it is being added before the containing panel has ever been correctly sized.

So the child control is being anchored not to the actual size as you see at design time but instead to the default size of a panel. So the child control will effectively be anchored against the default panel size and not the actual design time generated size.

Fortunately it took less time to fix the bug than it does to explain it!

The next release will have the fix included. If you are desperate and need the fix quicker then send me an email or post a message on the forum and I will send you an internal build.

Looking back I am really glad I went with using the simplest and easiest solution rather than try and use a technology for the sake of it. Adding a forum capability to the website using phpBB took just a couple of hours.

When I added the blogging feature I used a simple php piece of software called cuteNews that was a cinch to add and simple to use. Just because I am a windows developer some people expected I must use a Windows based server and use ASP.NET for everything. But why?

My products are going to be user interface components for smart clients based on .NET2. This is very much a client side market. So there is no need to say I must also stick to .NET for the server side of the website. If I was writing ASP.NET components then yes, I would ‘dog food’ my own controls.

Instead I choose to use php for the forums because I can add it in just a couple of hours and ‘it just works’. Most of that time was spent playing around with customizing the colors to match the main website. The software phpBB is free, well supported and familiar to all. I would highly recommend it.

Finally the day has arrived. The full version 1 release is now available and includes several useful changes over the previous beta release.

First of all documentation is now provided in a help file that integrates into the VS2005 help contents. This includes a couple of tutorials to help get you started with using the toolkit.

Also included are three palettes in the Palettes subdirectory so you can play around with some different look and feels straight away. You can of course use the new Palette Designer application to create your own.

Plus you now get the full source code to all the samples so you can see how they work in practice.

Enjoy!