Next Steps

Download the library.

View more detailed Documentation.

Learn techniques by watching Videos.

Introduction

These controls keep themselves up-to-date automatically. Create visually stunning, highly interactive Windows forms. Update Controls simplify UI programming. And the new tab control features inertia.

How it Works

With other controls, you set properties like "Text" to put data into the form. When the data changes, you have to set the property again. But with Update Controls, you implement events like "GetText". The controls automatically update themselves when the data changes.

The following code is all it takes to attach the First Name text box to the data object:

Public Partial Class ContactForm
    Inherits Form
    Private _contact As Contact

    Public Sub New(ByVal contact As Contact)
        _contact = contact
        InitializeComponent()
    End Sub

    Private Function firstNameTextBox_GetText() As String
        Return _contact.FirstName
    End Function

    Private Sub firstNameTextBox_SetText(ByVal value As String)
        _contact.FirstName = value
    End Sub
End Class

The data is stored in a simple object. We start by defining fields:

Public Class Contact
    Private _firstName As String
    Private _lastName As String
    Private _email As String
    Private _phone As String
End Class

Then we press Ctrl+D, Ctrl+G and the library generates dynamic properties:

Public Class Contact
    Private _firstName As String
    Private _lastName As String
    Private _email As String
    Private _phone As String

Dynamic properties
End Class

Finally, we add our own business logic:

    Public ReadOnly Property FullName() As String
        Get
            If String.IsNullOrEmpty(FirstName) AndAlso String.IsNullOrEmpty(LastName) Then
                Return "New Contact"
            Else
                Return String.Format("{0}, {1}", LastName, FirstName)
            End If
        End Get
    End Property

Now our data object is ready for any Update Controls that we want to attach to it. Now or in the future.

Download and Install

Update Controls requires Visual Studio .NET 2008. It adds controls to the Toolbox, and an add-in for generating dynamic properties. Once the installer finishes, open Visual Studio and start working on your first Update Controls application.

The Toolbox

Two sections were added to your toolbox. The Update Controls Themes section contains controls that have an appealing refractive three-dimensional look. These controls include ThemedButton, ThemedCheckBox, and ThemedRadioButton. These controls are better-looking versions of their standard counterparts. You also get the ThemedTabDeck, which gives you a tabbed document experience with reordering, closing, tab images, and best of all inertia. Here you will also find the Theme component, which controls the appearance of all controls in this section.

The Update Controls section contains the standard Windows controls with update behavior. These controls include UpdateTextBox, UpdateTreeView, and UpdateGrid. Build your forms using these controls instead of the standard Windows controls. To attach them to data, handle Get and Set events instead of setting properties.

The Contact Form

Start a new project and rename Form1 to ContactForm. Add four standard Labels and four UpdateTextBox controls. You don't need UpdateLabels for this step, since the label text is static.

It's a good idea to set the Anchor property on all four UpdateTextBox controls to "Top, Left, Right". This will cause the controls to stretch with the window.

The Contact Class

Add a new class to your project called Contact. You will have to make this class public. Add four private fields to the class:

Public Class Contact
    Private _firstName As String
    Private _lastName As String
    Private _email As String
    Private _phone As String
End Class

Now select the four fields and invoke the "Generate Dynamic Properties" command from the "Tools" menu, or just press Ctrl+D, Ctrl+G. The library will generate code for accessing these values.

The Get and Set Events

Go back to the ContactForm, right-click, and select "View Code". The form needs a Contact object to edit, so add a private Contact called "_contact". Add a constructor parameter to initialize this field.

Public Partial Class ContactForm
    Inherits Form
    Private _contact As Contact

    Public Sub New(ByVal contact As Contact)
        _contact = contact
        InitializeComponent()
    End Sub
End Class

Go back to the designer and select the first name text box. You may want to change its name to "firstNameTextBox" to make the code more readable. In the "Properties" window, click the lightning-bolt "Events" button. Double-click the event GetText, and have the method return _context.FirstName. Go back to the designer and double-click SetText. Have this method set _context.FirstName to the value parameter.

    Private Function firstNameTextBox_GetText() As String
        Return _contact.FirstName
    End Function

    Private Sub firstNameTextBox_SetText(ByVal value As String)
        _contact.FirstName = value
    End Sub

Do the same thing for the other controls, attaching them to the other properties.

The Program

Open the Program class and edit the Main method. The ContactForm takes a Contact object as a constructor parameter, so the Program has to supply it. Create one and pass it into the ContactForm constructor.

        Private Shared Sub Main()
            Application.EnableVisualStyles()
            Application.SetCompatibleTextRenderingDefault(False)
            Dim contactList As New ContactList()
            Application.Run(New MainForm(contactList))
        End Sub

For good measure, let's create a second form that edits the same contact. Add a line before Application.Run to show another one.

        Private Shared Sub Main()
            Application.EnableVisualStyles()
            Application.SetCompatibleTextRenderingDefault(False)
            Dim contactList As New ContactList()
            (New MainForm(contactList)).Show()
            Application.Run(New MainForm(contactList))
        End Sub

Now run this program and you will see that the two forms are linked to each other through their common Contact object.