Archive for October, 2005

There are two objectives for the components that I am writing. The first is to ensure that they look really good so that developers can quickly create professional looking applications. The second is to provide exceptional functionality around the area of managing the application workspace.

The Krypton Toolkit is going to be a free set of components and so can only offer a limited set of functionality. After all, we cannot give away the crown jewels for nothing! But it does need to deliver on the presentation side.

If the developer can use the controls to build a great looking application in only a couple of minutes then you have already impressed them. First impressions count because if you disappoint them in the first couple of minutes they will uninstall and look at another product.

Raising the users opinion of your product is very difficult, if not impossible over the short to medium term. It is much easier to start with a good impression and then work hard to maintaining that so it does not drop in the future.

Our default look and feel for all the controls is going to be called Professional Office 2003. Not a very catchy title but it indicates straight away that it is intended to give a professional look and feel that is consistent with the found in Microsoft Office 2003.

Here is a picture of an application that took about 60 seconds to create.

The distinctive blue color scheme will be familiar to all windows users that are running Windows XP with the default theme. If you switch to an alternative theme such as Silver then it will update to give the following appearance.

Of course, not all users are going to be running Windows XP and so it also mimics the Office 2003 look when used under the traditional windows classic scheme.

This will be our default look and feel because the majority of developers will want to mimic the appearance of Office 2003. Everyone uses the Office suite of applications and so end users will be instantly familair and at home with the appearance.

The second palette I have added to the toolkit is called Professional System and is very similar. Instead of using the current desktop theme to determine the blue/green/silver colorset it always uses the current system colors to calculate the appearance. This look and feel is therefore the same as for Visual Studio 2005 itself.

The next step is to create an easy to use component that the user can customize to create their own palette that is applied to all the toolkit controls and even the menu and toolbar area. That will allow the full flexibility of the controls appearance to be exposed.

You know what great General’s used to do with their armies in the old days. Land at the destination and then burn the ships. That way the troops know that the only way home is to win the battle on the way back.

A great motivator but I doubt it would go down very well today. Well I have been working for myself in my spare time for a few years on different projects and always saying to myself that I would quit the day job when the time was right.

Recently I came to the conclusion that there is never an ideal time to go it alone. There is always some excuse you can throw up to delay it just a little bit longer. In fact the longer you delay it the more of a habit it becomes to wait just a little bit more.

Well enough is enough. I have handed in my notice at work and will be officially freed from the shackles of employment on the 1st of Feb 2006.

But one change in your life is never enough and so I am also moving to Australia (from the UK) at the same time. Not for the rest of my life but to spend a few years enjoying the nice weather, sandy beaches and kangaroo burgers. Surely they have room for one more over there? As luck would have it I married an Ozzie sheila so I can sneak in without being a plumber (apparently they are in desperate need of plumbers over there).

Leaving my job and moving are not exactly the same risk as burning the only ship home but it is certainly a big step. I think it should be pretty easy to motivate myself during the long evenings now I have a date to target.

Now I need to start practicing the local lingo. See ya later cobber.

The easiest way to explain the addition of smart tag functionality to a control or component is to walk through a simple example. I have deliberately kept the example as simple as possible in order to make it quick and easy to see what is required from the additional code you need to write.

Step 1 – Create a new UserControl class

Create a new project and add a new UserControl class to your project. In our example we will add the smart tag to a UserControl but in practice you could add it to any of your existing controls or components.

Drag a new instance of the control onto your Form and then select it. This will result in something even less exciting than this picture of the selected control on the Form.

I customized my control by changing the background color, asking for a border to be drawn and then painting a string in the client area. The full code for the example generated from these steps is available from a link at the end of the article, so there is no need to type in the code from each step.

Step 2 – Add the designer attribute

We need to provide a customized designer for the control in order to provide the information the design time environment needs for showing the smart tag. In order to associate a designer class with the control class we add the following attribute to the control class definition.

[Designer(typeof(UserControl1Designer))]
public class UserControl1 : UserControl

Step 3 – Implement the designer class

The default designer associated with a UserControl is called ControlDesigner and so our custom designer class derives from this. Extending the designer involves overriding just a single property of the base class called ActionLists. This is used to return to the caller a collection of lists that are used to populate the smart tag window.

The default implementation from the ControlDesigner returns an empty collection, hence the absence of the smart tag button when you select the control at design time. Our implementation creates an action list and adds it to the list collection. Here is the complete code for the class.

public class UserControl1Designer : ControlDesigner
{
  public override
             DesignerActionListCollection ActionLists
  {
    get
    {
      DesignerActionListCollection actionLists =
          new DesignerActionListCollection();

      actionLists.Add(
          new UserControl1ActionList(this));

      return actionLists;
    }
  }
}

Step 4 – Implement an action list

This is the class that performs the real work. All action lists must derive from the DesignerActionList base class. We provide a constructor that takes a reference to the designer instance and used it to cache a reference to the control instance.

public class UserControl1ActionList
    : DesignerActionList
{
  private UserControl1 _control;

  public UserControl1ActionList(
      UserControl1Designer owner)
    : base(owner.Component)
  {
    _control = (UserControl1)owner.Component;
  }


Our simple example is going to expose a BackColor entry on the smart tag window that alters the property with the same name on the UserControl1 instance. Whenever you provide a property action you need to implement the property on the action list class itself. Our implementation of the BackColor just calls onto the underlying UserControl1 instance that was cached in the constructor.

  public Color BackColor
  {
    get { return _control.BackColor; }
    set { _control.BackColor = value; }
  }


Our last task is to override the GetSortedActionItems method. This is the method that returns a collection of items that are required to be displayed on the smart tag window. In our case we need to add just a single entry for the BackColor.

  public override DesignerActionItemCollection
      GetSortedActionItems()
  {
    DesignerActionItemCollection actions =
        new   DesignerActionItemCollection();

    actions.Add(new DesignerActionPropertyItem(
                      "BackColor",
                      "BackColor",
                      "Appearance",
                      "Background color."));

    return actions;
  }
}

Step 5 – Compile and open in design mode

Once you have compiled the above code you should be able to select an instance of the UserControl1 control at design time and then access the defined smart tag. You can see it here in it’s full glory!

You can download the source code for this sample from here.

Developing as a lone wolf has some great advantages. Writing all the code yourself ensures that everything is written in a consistent manner and towards your own vision. No more compromises to fit in with a team leader or technical architect’s idea of how things should work.

My experience so far also indicates that you tend to write a higher quality of code. When you know that your income will depend on the quality of what you create it concentrates the mind wonderfully. Instead of being happy to produce good code, now the only benchmark that makes me happy is great code. It has to be just right.

Of course, what is considered good or great is subjective. My great code might be only average from your point of view and visa versa. But the important point is that you are writing code at the limit of your ability and would be happy to be judged by it.

The down side to being a lone developer is that you have no one to turn to when you get stuck. If you have a tricky decision to make there is no one to bounce ideas off, no alternative point of view to attack a problem with. But there is a solution of sorts.

I have just enrolled on the Microsoft ISV Buddy program. This is a scheme from Microsoft that pairs you up with a developer inside Microsoft, giving you a direct line to an internal developer. Even if they cannot answer the problem themselves, they probably know someone else who can.

If your developing for .NET and working either on your own or in an ISV then I recommend you give it a try. Here is the link…

http://msdn.microsoft.com/isv/isvbuddy/default.aspx

Although my blog has been very quite for the last couple of weeks, I have still been hard at work. Just completed this weekend is the Krypton SplitContainer control. This is the Krypton version of the SplitContainer control that comes with the soon to be released Visual Studio 2005.

The intention is not to provide different functionality from the standard SplitContainer but to provide a version that works within the Krypton framework. So it uses the correct appearance as defined by the palette and renderer from the Krypton Toolkit.

This is how it looks at design time with the default Professional palette and renderer.

The container has two panels separated by the position of the splitter. When the panels have no child controls on their surface they show the name of the panel in the centre. Once the user places a control on the panel surface the name watermark is removed.

If you have not used any of the Visual Studio 2005 beta versions then you will not yet be aware of some of the great new changes that are coming up. One of my favorites is the smart tag.

When you select the control at design time it shows the following appearance.

As you would expect, you get a focus rectangle around the control with resizing handles along the edges. If you look at the top left there is a small box that is used to drag the control to a different screen location. This is much easier to use than the old method of dragging the focus rectangle.

At the top right is a little arrow button, this is called the smart tag. When you click this arrow button it shows a popup window with options that can be used to quickly change aspects of the control.

This is a quick way to perform changes to the control without having to navigate to the Properties window and search for the property of interest.

Here is the smart tag display when you press the button for the Krypton SplitContainer control.

So now if you want to alter the splitter from being a vertical to a horizontal split, you just click the smart tag button and press the appropriate command as shown in the picture above.

I have gone ahead and added appropriate smart tags definitions for each of the Krypton controls. It is tempting to add a long list of options but I have restrained myself to just a small set of the obviously useful ones.

I expect smart tags to speed up the time it takes developers to quickly customize controls and also to make it easy for them to discover functionality when first using them.