Everyone who is familiar with the Windows Home Server user interface has seen LineBox in action. It’s used by Microsoft to group configuration sections in the Settings dialog box, and provides developers with a UI element that compliments the rest of Windows Home Server.

Here is an example of LineBoxes used in anger:

image

The problem with LineBox is that it wasn’t ever created to be used in the Visual Studio forms designer. This makes it a pain to layout clean interfaces using LineBox in a graphical view. These are the things you can’t change in the designer, but should be able to:

  • Title text
  • Title font
  • Title font colour
  • Spacing between the title text and the line

You can tweak all these things in code, but I’ve been using so many LineBoxes recently that I decided to extend it to make it a more designer-friendly control.

Here’s the result:

using System.Drawing;
using Microsoft.HomeServer.Controls;

namespace Microsoft.HomeServer.HomeServerConsoleTab.DiskMgt.Gui
{
    public class DesignerLineBox : LineBox
    {
        public string Title
        {
            get
            {
                return Header.Text;
            }
            set
            {
                Header.Text = value;
            }
        }

        public Font TitleFont
        {
            get
            {
                return Header.Font;
            }
            set
            {
                Header.Font = value;
            }
        }

        public Color TitleColor
        {
            get
            {
                return Header.ForeColor;
            }
            set
            {
                Header.ForeColor = value;
            }
        }

        public int LineMargin
        {
            get
            {
                return LineHoriz;
            }
            set
            {
                LineHoriz = value;
            }
        }
    }
}

Now I can drag my DesignerLineBox off the Toolbox in Visual Studio, right into the designer, and change the text, font, and line spacing without having to do it in code and constantly check the results in the WHS Console.

image

Quick and easy, and it’ll save me loads of time.

posted on Sunday, July 12, 2009 4:43 PM | Filed Under [ Windows Home Server Development ]

Comments

Gravatar
# re: Making LineBox designer-friendly (Martin Rothschink @ 7/13/2009 7:13 PM)

Thanks Sam,
will save my time too.

Regards
Martin
 
Gravatar
# re: Making LineBox designer-friendly (Andreas M. @ 7/14/2009 5:36 AM)

You might want to mark the Title property with a [Localizable] attribute, so that you can use the Windows Forms designer to create multilanguage (localized) versions of your UI.
 
Gravatar
# re: Making LineBox designer-friendly (Sam Wood @ 7/14/2009 9:29 AM)

Great idea, Andreas.

 
Gravatar
# re: Making LineBox designer-friendly (TxDot @ 7/15/2009 9:56 AM)

Thanks Sam. Another good tip.

Post Comment

Title *
Name *
Email
Url
Comment *  
Remember me
Please add 2 and 7 and type the answer here:

Search

Site Sections

Recent Posts

Archives

Post Categories

WHS Add-In Tutorial

WHS Blogs

WHS Development