Click here to Skip to main content
Click here to Skip to main content

Microsoft Outlook Style Headers

, 9 Dec 2002
Rate this:
Please Sign up or sign in to vote.
Creating Panel Effect Label like Outlook
<!-- Article image -->

Sample Image - HeaderLabel.jpg

<!-- Add the rest of your HTML here -->

Introduction

Have you ever wondered how in C# to get borders onto visual objects; coming from a Delphi background I was very familiar with having visual controls that offered border effects such as "Etched" or "Sunken" amongst many others. Well, the .NET framework does have this functionality, you just have to impliment it yourselves. The following article will show you how I have taken a simple label object, and applied this logic to obtain a component that offers me the standard microsoft look and feel from programs like Outlook.

Details

Ok, so lets just take a look at the code. Firstly, I need some local properties to allow any of this drawing to take place, I add a visual property called BorderLine, and when set to true, the OnPaint will do our desired drawing, also making use of the so far unused Border3DStyle Enumeration. We set up a property of this type and then set it to Etched as default.

private bool borderLine = true;
private Border3DStyle borderLineStyle = Border3DStyle.Etched;

We then offer the functionality assigned to these two new properties, so that when changed either at runtime or in the ide, they trigger all neccessary redrawing to be done.
[
Category("Appearance"),
Description("Set to True to work with BorderLineStyle" + 
    " To create border effect.")
]
public bool BorderLine {
  get {
    return borderLine;
  }

  set {
    if( value != borderLine ) {
      borderLine = value;
      Invalidate();
    }
  }
}

[
Category("Appearance"),
Description("Add a 3D Style border effect")
]
public Border3DStyle BorderLineStyle {
  get {
    return borderLineStyle;
  }
  set {
    if( value != borderLineStyle) {
      borderLineStyle = value;
      Invalidate();
    }
  }
}

Finally, the Invalidate(); will cause the OnPaint event to be called within the control.
protected override void OnPaint(PaintEventArgs pe) 
{
  base.OnPaint(pe);      
      
  if (borderLine) 
  {
    ControlPaint.DrawBorder3D(pe.Graphics,ClientRectangle.Left+1,
        ClientRectangle.Top +1, 
ClientRectangle.Width -1, 
ClientRectangle.Height -1, 
borderLineStyle);        
  }  
}

Conclusion

This is the real crux of the whole thing, there is a method called DrawBorder3D that accepts the client area to use, and a Border3DStyle to draw on it.

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

About the Author

CodeSlinger
Web Developer
United Kingdom United Kingdom
Does anyone actually read this ? ok, if you do, I used to be a general manager of a computer software company, I developed the applications in Delphi C/S (all versions 2,3,4,5,6). I now am a senior developer for a software company, the language of choice being C#. Although I am a beginner, I hope to become more preficiant in this language as the time goes by.
 
Cheers for reading if in fact you did actually bother.

Comments and Discussions

 
GeneralAlways include the entire solution, please. PinmemberNo Email14-Oct-05 11:37 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 10 Dec 2002
Article Copyright 2002 by CodeSlinger
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid