Click here to Skip to main content
13,289,107 members (54,822 online)
Click here to Skip to main content
Add your own
alternative version


22 bookmarked
Posted 1 Mar 2004

Hello Longhorn

, 1 Mar 2004
Rate this:
Please Sign up or sign in to vote.
Introduction to programming under Longhorn.


This article introduces you to programming for the next version of Windows codenamed Longhorn. (In order to understand the codename jargon, please read The perplexed guide for the new codenames of Microsoft.) Now getting back to the point, Longhorn when released will change the landscape for developers in a significant way. Although most of the old stuff from COM (isn’t that old enough), .NET (Bye Bye WinForms) will work smoothly, the new technologies such as Avalon, WinFS, Indigo provide a much better and richer base to work with.

I will take you through a very simple program, which responds to a click on a button control and displays "Hello Longhorn". The code is entirely written in C#. I have used MSBuild to compile my code (I still do not have my hands on Whidbey). In a sequel to this article, I will show you how to write the same program in a new revolutionary way using XAML. But for now, let’s stick to vanilla C#.

Getting to the business

The figure below is what our killer application will look like. By looking at it, if you figured out that it has a window, a button and a text box, then pat yourself, because that’s what there is to it. It has another goodie called Canvas, and I will tell you about it in a minute. Here’s the picture:

Okay, now that you are done looking at this piece of exceptional artistry, I will show you how it’s done.

As usual, we start with our import statements:

using System;
using MSAvalon.Windows;
using MSAvalon.Windows.Controls;

Next, we create a class:

public class TextBoxApp : Application

Application is the top-level object, and all applications should inherit from this class. You can also inherit from the NavigationApplication class for Longhorn Navigation Applications.

Next, I declare a few controls:

MSAvalon.Windows.Controls.TextBox myTextBox;
MSAvalon.Windows.Controls.Button myButton;
MSAvalon.Windows.Controls.Canvas myCanvas;

Although I have my import statements at the top, I still like to use the full namespace. I feel that this helps me in learning about the new framework.

We then override a method from the base class which is the Application class. This method is always called when an application is started.

protected override void OnStartingUp(StartingUpCancelEventArgs e)
    base.OnStartingUp(e); //call the method in the base class
    CreateWindow(); //call a private method to create the window

Now, we will implement our private method, which is the meat of the application. This method will create a window, put a Canvas and then put other controls on top of the Canvas. Canvas class, which is located in the MSAvalon.Windows.Controls namespace, is one of the panels available in Avalon (the new presentation system under Longhorn). Below is the complete method:

private void CreateWindow()
    //create main window
        MSAvalon.Windows.Window myWindow = new MSAvalon.Windows.Window();
        myWindow.Width = new Length(300);
        myWindow.Height = new Length(170);

        //Add a canvas to the window
        myCanvas = new MSAvalon.Windows.Controls.Canvas();

        myCanvas.Background =  MSAvalon.Windows.Media.Brushes.LightSteelBlue;
        myCanvas.Width = new Length(100,UnitType.Percent);
        myCanvas.Height = new Length(100,UnitType.Percent);

        //Add a Text Box to the canvas
        myTextBox = new MSAvalon.Windows.Controls.TextBox();
        myTextBox.Width = new Length(200);
        myTextBox.Height = new Length(40);
        MSAvalon.Windows.Controls.Canvas.SetTop(myTextBox, new Length(30));
        MSAvalon.Windows.Controls.Canvas.SetLeft(myTextBox, new Length(50));


        //Add a button to the canvas
        myButton = new MSAvalon.Windows.Controls.Button();
        MSAvalon.Windows.Controls.Canvas.SetTop(myButton, new Length(100));
        MSAvalon.Windows.Controls.Canvas.SetLeft(myButton, new Length(110));
        myButton.Content = "Click Me";

        //Add a event handler for Click Event
        myButton.Click += new ClickEventHandler(OnClick);

        //show the window

    catch(Exception ex)

I will point your attention to a particular line in the code:

myButton.Content = "Click Me";

Note that there is no Text property for the Button control.

I have also specified an event handler for myButton's Click event. All that this handler will do is change the text in my text box:

void OnClick(object sender, ClickEventArgs e)
        myTextBox.Text = "Hello Longhorn";
    catch(Exception ex)

Next, we need to provide a main method that will run our application. I have my main method in my EntryClass. I have marked it as sealed, because I never wish to inherit from this class (you don’t need to do this).

public sealed class EntryClass
    private static void Main ()
        TextBoxApp app = new TextBoxApp ();
        app.Run ();

As I do not have Whidbey, I used MSBuild to compile my project. You will need a project file, which is included in the code download with this article. A project file tells MSBuild about what kind of application this is, what files are included, and a few other things. Make sure that you have both project and the source files in the same folder.

In order to build the application successfully, launch your build environment from Start - All Programs - Microsoft Longhorn SDK - Open Build Environment Window - Longhorn Build Environment. Change to the directory where you have the project and the source file, and type:

msbuild SimpleWinApp.csproj

and hit Enter. You should have an EXE in the Release folder under your current directory. Click on the EXE and enjoy the application.

For all Longhorn nuts, I recommend a daily visit to Longhorn Developer Centre.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Deepak Kapoor
Australia Australia
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralThank you! Pin
FinishedOnTime22-Mar-07 6:15
memberFinishedOnTime22-Mar-07 6:15 
GeneralDoesn't work on PDC build Pin
Tom Archer - MSFT22-Sep-05 11:36
memberTom Archer - MSFT22-Sep-05 11:36 
GeneralExtending this example Pin
TadejK16-Jan-05 9:09
memberTadejK16-Jan-05 9:09 
GeneralRe: Extending this example Pin
Deepak Kapoor16-Jan-05 16:57
sussDeepak Kapoor16-Jan-05 16:57 
GeneralRe: Extending this example Pin
TadejK16-Jan-05 21:08
memberTadejK16-Jan-05 21:08 
GeneralRe: Extending this example Pin
Deepak Kapoor17-Jan-05 0:46
sussDeepak Kapoor17-Jan-05 0:46 
GeneralLonghorn sdk Pin
ko_dk20-Apr-04 6:41
memberko_dk20-Apr-04 6:41 
GeneralRe: Longhorn sdk Pin
Deepak Kapoor20-Apr-04 13:57
memberDeepak Kapoor20-Apr-04 13:57 
GeneralRe: Longhorn sdk Pin
ko_dk20-Apr-04 20:34
memberko_dk20-Apr-04 20:34 
GeneralRe: Longhorn sdk Pin
Anonymous1-Aug-04 17:06
sussAnonymous1-Aug-04 17:06 
General.Net Framework v1.2.30703? :confused: Pin
RisingPhoenix23-Mar-04 3:44
memberRisingPhoenix23-Mar-04 3:44 
GeneralRe: .Net Framework v1.2.30703? :confused: Pin
Deepak Kapoor25-Mar-04 17:28
memberDeepak Kapoor25-Mar-04 17:28 
GeneralRe: .Net Framework v1.2.30703? :confused: Pin
RisingPhoenix25-Mar-04 19:38
memberRisingPhoenix25-Mar-04 19:38 
GeneralRe: .Net Framework v1.2.30703? :confused: Pin
Deepak Kapoor25-Mar-04 19:45
memberDeepak Kapoor25-Mar-04 19:45 
Generaltypical MS!! Pin
Paul Griffin12-Mar-04 6:33
memberPaul Griffin12-Mar-04 6:33 
GeneralRe: typical MS!! Pin
Marcie Robillard (Datagrid Girl)12-Mar-04 7:10
staffMarcie Robillard (Datagrid Girl)12-Mar-04 7:10 
GeneralRe: typical MS!! Pin
JoeMarini8-Apr-04 11:11
memberJoeMarini8-Apr-04 11:11 
GeneralRe: typical MS!! Pin
WillemM7-May-04 1:08
memberWillemM7-May-04 1:08 
GeneralAbout the MSAvalon namespace Pin
Marc Clifton2-Mar-04 2:28
editorMarc Clifton2-Mar-04 2:28 
GeneralRe: About the MSAvalon namespace Pin
dog_spawn2-Mar-04 14:19
memberdog_spawn2-Mar-04 14:19 
GeneralRe: About the MSAvalon namespace Pin
Deepak Kapoor2-Mar-04 22:57
memberDeepak Kapoor2-Mar-04 22:57 
GeneralRe: About the MSAvalon namespace Pin
Norm Almond8-Mar-04 3:12
memberNorm Almond8-Mar-04 3:12 
GeneralRe: About the MSAvalon namespace Pin
Ryan Beesley27-Apr-04 0:40
memberRyan Beesley27-Apr-04 0:40 
GeneralRe: About the MSAvalon namespace Pin
Keith Hill4-Mar-04 21:52
sussKeith Hill4-Mar-04 21:52 
GeneralRe: About the MSAvalon namespace Pin
Frank Hileman9-Mar-04 5:00
memberFrank Hileman9-Mar-04 5:00 
GeneralRe: About the MSAvalon namespace Pin
Martin Stampe10-Mar-04 3:07
memberMartin Stampe10-Mar-04 3:07 
GeneralWrong image URL Pin
szaddam2-Mar-04 1:48
memberszaddam2-Mar-04 1:48 
GeneralRe: Wrong image URL Pin
Marc Clifton2-Mar-04 2:22
editorMarc Clifton2-Mar-04 2:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 2 Mar 2004
Article Copyright 2004 by Deepak Kapoor
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid