Click here to Skip to main content
16,023,224 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi

How to change Form Border Color.It is possible or not.
Posted
Updated 24-Mar-20 8:07am
v2

It isn't simple, certainly, and is probably more trouble than it's worth - the border is outside the app's control (to maintain a consistent look and feel it is part of the OS rather than the app) and the only direct control you have is to remove the border and draw it yourself - that would remove the ability to resize the form however.

There is one sample I have seen: http://customerborderform.codeplex.com/[^] - but I have no idea how much work you are going to have to do to get it working in your code.
 
Share this answer
 
Another option for that problem is
1 - firstly change Form property formBorderStyle to none.
2 - Use panel and set as content of form content and change form backgroundcolor red or other color which you want to use for your border.
3 - Add a button on top-left side of for closing the for
4 - make form draggable

I had using that trick properly
 
Share this answer
 
v2
Steps:

1. Set FormBorderStyle to None.
2. Get a Panel set Panel.Dock to Top and adjust the size.
3. Choose the desired color of Panel.
4. Make the Event Panel_MouseDown to make the Form Draggable


// Drag Form
        [DllImport("user32.DLL", EntryPoint = "ReleaseCapture")]
        private extern static void ReleaseCapture();
        [DllImport("user32.DLL", EntryPoint = "SendMessage")]
        private extern static void SendMessage(System.IntPtr hWnd, int wMsg, int wParam, int lParam);
        
        private void TopPanel_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(this.Handle, 0x112, 0xf012, 0);
        }
        
        // Close-Maximize-Minimize
        private void CloseIconButton_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void MaximizeIconButton_Click(object sender, EventArgs e)
        {
            if (WindowState == FormWindowState.Normal)
            {
                WindowState = FormWindowState.Maximized;
                FormBorderStyle = FormBorderStyle.None;
                MaximizeIconButton.IconChar = FontAwesome.Sharp.IconChar.WindowRestore;
            }
            else
            {
                WindowState = FormWindowState.Normal;
                MaximizeIconButton.IconChar = FontAwesome.Sharp.IconChar.Square;
            }
        }

        private void MinimizeIconButton_Click(object sender, EventArgs e)
        {
            WindowState = FormWindowState.Minimized;
        }
        #endregion



This Is as far as I came to it. But it does not make Form Resizeable so it is not very interactive...
 
Share this answer
 
C#
private void Form_Paint(object sender, PaintEventArgs e)
{
    e.Graphics.Clear(this.BackColor);
    ControlPaint.DrawBorder3D(e.Graphics, this.ClientRectangle, Border3DStyle.Etched, Border3DSide.All);
}
private void Form_Resize(object sender, EventArgs e)
{
    this.Invalidate();
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900