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.
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)
{
TitledForm_ResizeBegin(sender, e);
}
private void lblSubTitle_LocationChanged(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Maximized)
{
IsMaximized = true;
TitledForm_ResizeEnd(sender, e);
}
else
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)