Click here to Skip to main content
14,776,131 members
Articles » Languages » C# » General
Posted 11 Apr 2007


24 bookmarked

A Form with Customized Caption Bar and Flexible Border

Rate me:
Please Sign up or sign in to vote.
2.89/5 (16 votes)
11 Apr 2007CPOL
An article on how to customize caption bar (e.g. displaying image on caption bar) and change border width and border color.
Screenshot - customizedForms.jpg


First of all, I want to say that I am a novice in C# and this is my first article. So, I would like to apologize to the experts if they do not find anything useful in this article. But I think there may be someone out there who needs this article.

We know that it is not a very easy task to customize the caption bar and the border of a form. You can see that Microsoft-Office 2007 or Yahoo Messenger for Windows Vista displays images on its caption bar. This article chronicles the way to customize the caption bar and set the border width and border color of the form as per your needs.

How I Did It

I set the border style of the form to none and used some picture boxes to draw the borders. I made a user control with three buttons to minimize, maximize and close the form. I used a panel on the top and a picture box on the top-left corner of the form to create the caption bar.

Some Properties and Methods

Here is a list of some properties and methods that you can use in your code:

  • int BorderWidth: Gets or sets the width of the form border
  • Color BorderColor: Sets the border color of the form
  • bool MinimizeButton: Shows the minimize button if true else, hides the minimize button
  • bool MaximizeButton: Shows the maximize button if true else, hides the maximize button
  • bool CloseButton: Shows the close button if true else, hides the close button
  • bool MinMaxCloseButtons: Shows all the three buttons if true else, hides all the three buttons
  • int MinMaxCloseHeight: Gets or sets the height of the min, max and close buttons
  • void HideBorders(): Hides form border
  • void ShowBorders(): Shows form border

Using the Code

Using this code is very simple. Add CustomizedForms.cs and Min_Max_Close.cs along with their designer and resource files to your project. Inherit your form from CustomizedForms instead of System.Windows.Forms.Form.

Your class declaration would be:

public partial class CustomizeFormExample : CustomizedForm 

You can use panels, picture boxes or any other control to design your caption bar. To make your form pan-able, you just add the following codes in the mouse down, mouse move and mouse up events of the controls that you are using for your caption bar.

bool Active = false;
int X = 0,Y=0;

private void CaptionBar_MouseDown(object sender,MouseEventArgs e)
    Active = true;
    X = e.X;
    Y = e.Y;

private void CaptionBar_MouseMove(object sender, MouseEventArgs e)
    if (Active)
        this.Location = new Point(this.Left + e.X-X, this.Top + e.Y-Y);

private void CaptionBar_MouseUp(object sender, MouseEventArgs e)
    Active = false;


  • 11th April, 2007: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Arijit Datta
Web Developer
India India
Arijit is a young Programmer living in Kolkata
who started his career as a C# developer. He is very humorous and friendly and a great dreamer.He loves wild life, his friends and his family.
Arijit was born in a small and beautiful town
named Cooch Behar in India.He started programing
when he was in high school.
Arijit is presently working in Citytech Solutions
as a software engineer and he likes to share his thoughts and views with others.
To contact Arijit, email him at

Comments and Discussions

Questiongood job but i have a question Pin
elaznajib2-Nov-14 15:40
Memberelaznajib2-Nov-14 15:40 
QuestionLet the user resize a form that has no title bar or borders Pin
mr.fugio23-Jul-13 6:26
Membermr.fugio23-Jul-13 6:26 
QuestionHow to add a menue strip to the form Pin
Steven.Pinto200026-Dec-12 19:22
MemberSteven.Pinto200026-Dec-12 19:22 
GeneralMy vote of 1 Pin
mohammadrezaasadi26-Jun-12 2:32
Membermohammadrezaasadi26-Jun-12 2:32 
GeneralGood Work Pin
dickinson.jonathan9-Sep-07 23:29
Memberdickinson.jonathan9-Sep-07 23:29 

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.