Making something as simple as a KryptonTextBox sound interesting is going to be tough work. In fact I don’t think I can manage it. Still, the KryptonTextBox is an essential additional to the Toolkit because it is hard to think of many client applications that do not need to use at least one. Our control is really just a standard windows TextBox placed inside a container that provides the correct colors to use and then draws the border manually.
Here you can see three KryptonTextBox instances on the left side and three standard WinForms TextBox instances on the right hand side. The Office 2007 Silver color scheme has been selected.

And now in the Professional Office 2003 palette…

Because the border is drawn by the Krypton renderer it means we can customize the border in the same way as any other Krypton control. So here it is with the thickness increased and some rounding added to the corners.

An additional feature that you might find useful is the Active state. When the control has the focus, or the mouse is tracking over the control, it is considered to be in the Active state. There is a property called StateActive that allows you to determine the appearance when Active. So in this example I can changed the border color to be Orange so that as the user moves the mouse over the control it highlights nicely.

There is a restriction with setting the appearance of the KryptonTextBox. The background and text colors can only be simple solid colors. Unlike other Krypton controls you cannot use a gradient effect or image as the source for painting the background/text. In practice this should not be too restrictive.
September 27th, 2007 at 4:07 pm
nice. this is what i did to make a textbox with krypton borders.
will there be a feature for button specs (to use them as a dropdown or numeric updown feature)?
September 27th, 2007 at 10:32 pm
I found an article on how to ownerdraw the TextBox (to draw red lines under wrong words)… Couldn’t we do the same for borders and background (and even Text as well ?)… ? (just a question, I’m not an expert in Wforms controls rendering like you are so … ;-))
Thanks anyway for still improving the Toolkit!
September 27th, 2007 at 10:32 pm
Sorry, forgot the URL of the article I was talking about:
http://www.codedblog.com/2007/09/17/owner-drawing-a-windowsforms-textbox/
September 29th, 2007 at 9:16 pm
Thanks for the article but it does not really help. You need to let the underlying Win32 control do the actual drawing of the text and therefore you are limited to specifying a single text color. Also if you let the control draw the text you automatically get the background as well.
October 2nd, 2007 at 1:25 am
Absolutely brilliant, Phil. Great work, I can’t say it enough.
January 24th, 2008 at 8:49 pm
I have several Krypton text boxes on a form. There is a kryptonmanager and a kryptonpalette associated with the form.
I want the each control’s borders to be Orange when that control gets focus, which should get back to normal when the focus is lost. – The textbox’s Inputcontrolstyle is set as Standalone.
- So I set the KryptonPalette->InputControlStyles->InputControlStandalone->StateActive->Border->Color1 to (255,128,0) in the properties box.
When I do this all the textboxes on the form show borders as Orange in design mode! and also on running the form the borders stay orange for all textboxes irrespective of focus!
Can you suggest what am I doing wrong? I have version 2.7.1 of the toolkit.
Thanks in advance.
January 24th, 2008 at 9:38 pm
You need to change the AlwaysActive property to be False. By default it is True and therefore the StateActive is applied all the time. At design time it always shows as Active so you need to run before seeing the difference it makes.