locked
Change Form Border Color

    Question

  • Hi,

     

    How do I change the color of my Windows Form border from its default blue color?

     

    Thanks.

     

    Wednesday, May 28, 2008 2:21 PM

Answers

  • Hi obrienkev ,

    As far as I know, the border is drawn by Windows, but you can set FormBorderStyle to “None” and draw a border by yourself.  However, removing the border also removes the ability to resize, so I think it is not a good idea to re-draw the form border.

    I have an idea to implement the appearance just like changed border color. Well, you can cover the form client area with a panel, and panel’s backcolor is not as same as the form, and handle the form resize event, please keep in mind, other windows form controls should be put onto the panel instead of the form, please check the code snippet below.

    Code Snippet

    public partial class Form1 : Form

        {

          

            public Form1()

            {

                InitializeComponent();

     

                this.BackColor = Color.Red;

     

                panel1.Location = new Point(5, 5);

                panel1.BackColor = Color.Green;           

               

            }

     

            private void Form1_Resize(object sender, EventArgs e)

            {

                panel1.Location = new Point(5, 5);

                panel1.Width = this.ClientRectangle.Width - 10;

                panel1.Height = this.ClientRectangle.Height - 10;

            }

    }

     

     

    Regards,

    Xun

     

    Friday, May 30, 2008 8:18 AM

All replies

  • Hi obrienkev ,

    As far as I know, the border is drawn by Windows, but you can set FormBorderStyle to “None” and draw a border by yourself.  However, removing the border also removes the ability to resize, so I think it is not a good idea to re-draw the form border.

    I have an idea to implement the appearance just like changed border color. Well, you can cover the form client area with a panel, and panel’s backcolor is not as same as the form, and handle the form resize event, please keep in mind, other windows form controls should be put onto the panel instead of the form, please check the code snippet below.

    Code Snippet

    public partial class Form1 : Form

        {

          

            public Form1()

            {

                InitializeComponent();

     

                this.BackColor = Color.Red;

     

                panel1.Location = new Point(5, 5);

                panel1.BackColor = Color.Green;           

               

            }

     

            private void Form1_Resize(object sender, EventArgs e)

            {

                panel1.Location = new Point(5, 5);

                panel1.Width = this.ClientRectangle.Width - 10;

                panel1.Height = this.ClientRectangle.Height - 10;

            }

    }

     

     

    Regards,

    Xun

     

    Friday, May 30, 2008 8:18 AM
  • There must be a Win32 API that allows this? But it would probably be more trouble then its worth

    Friday, May 30, 2008 4:21 PM