Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Titled Window Form

0.00/5 (No votes)
8 Jun 2007 1  
An article on a form that looks like a Windows Installer form

Screenshot - FormExample.png

Introduction

This article describes how to use the TitledForm class form with a nice view. The main idea in this project is to use simple .NET GDI to paint the necessary elements of a window -- such as lines, for example -- as well as to emulate text shadow.

Using the code

The first step is to create a new form; then you need to inherit from TitledForm. In order to do this, you have to add the TitledForm source file to your project, as outlined in the following code:

namespace TitledWindowTest
{
    public partial class Form1 : Chelindbank.Tools.WinForms.TitledForm
    {
        ///.......

    }
}

After this step, Form1 will have the parameters outlined below, which you can find in the Form Designer Properties window under the Titles section:

  • MainTitle - This is used to set the MainTitle label text in a caption at the top of the form.
  • Description - This is used to set the Description label text in a caption at the top of the form.
  • SubTitle - This is used to set the SubTitle label text at the bottom of the form.

Screenshot - ClearTitledForm.png

As a final step, you can set the parameters as follows:

void Form_Load(object sender, EventArgs e)
{
    this.Description = "Make your choise";
    this.MainTitle = "My application name";
    this.SubTitle = "The super app";
}

Changes

The latest update includes processing maximization and restoring of form state events. When the SubTitle label location is changed, we catch it and check if its state of form is Maximized. If it is, we invalidate the new region of the bottom line and invalidate the previous region of the line to clear it. To store the latest position of SubTitle and its line, we store its location after each resize.

private void TitledForm_ResizeEnd(object sender, EventArgs e)
{
    // .........<skipped>.........

    TitledForm_ResizeBegin(sender, e);
}
        
private void lblSubTitle_LocationChanged(object sender, EventArgs e) 
{ 
    /// Form is needed to be recalculated 

    if (WindowState == FormWindowState.Maximized) 
    { 
        IsMaximized = true; 
        TitledForm_ResizeEnd(sender, e); 
    } 
    else 
    /// Is needed to be recalculated again 

    if (WindowState == FormWindowState.Normal && IsMaximized) 
    { 
        IsMaximized = false; 
        TitledForm_ResizeEnd(sender, e); 
    } 
}

History

  • 4 June, 2007 -- Original version was posted to the main CodeProject.com article base
  • 8 June, 2007 -- Article and downloads updated (see Changes section)

License

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