Click here to Skip to main content
15,891,033 members
Articles / Desktop Programming / Windows Forms
Article

Titled Window Form

Rate me:
Please Sign up or sign in to vote.
1.00/5 (13 votes)
8 Jun 20071 min read 24.2K   300   24   4
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:

C#
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:

C#
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.

C#
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


Written By
Software Developer
Russian Federation Russian Federation
I finished university few years ago - South-Ural State University (SUSU).
Now I'm working as a programmer in bank...
And I'm trying to specialize in several sphere:

Programming: .NET, C++, Java;
Technology: J2EE (Oracle Application Server);
DataBases: Oracle, MSSQL, Microsoft JET;
Web: ASP, JavaScript, XML+XSLT, HTML making-up;
Using cryptography...

Comments and Discussions

 
QuestionTitledForm or UserControl? Pin
bocca018-Nov-09 11:25
bocca018-Nov-09 11:25 
AnswerRe: TitledForm or UserControl? Pin
dr.TyGER (Konstantin)8-Nov-09 23:21
dr.TyGER (Konstantin)8-Nov-09 23:21 
Generalerror when maximzed form Pin
adamsmin4-Jun-07 19:43
adamsmin4-Jun-07 19:43 
GeneralRe: error when maximzed form Pin
dr.TyGER (Konstantin)4-Jun-07 21:07
dr.TyGER (Konstantin)4-Jun-07 21:07 

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.