Bunifu Form Control Box
Maximize, Restore, Minimize, and Close a borderless Windows Form

Overview

Bunifu Form Control Box is a rich set of window control buttons (i.e. Minimize, Maximise/Restore, and Close) that allow you to set the visual state of a borderless Windows form. Icing on the cake:- you don't need to have to code the functionalities of minimizing, maximizing, restoring, or closing the form.
Here's a demo of an application using a Bunifu Form Control Box:

Getting started

Adding Bunifu Form Control Box at Design Time

Step 1: First, make sure that the Windows form is borderless. You can do this either by setting the property FormBorderStyle to none.
Step 2: Add Bunifu Form Control Box. Bunifu Form Control Box can be added to the form by dragging a BunifuFormControlBox control from the toolbox. It can be placed at the top-right corner of the Windows Form as shown below:
And…that’s it! We have implemented all view states of the form without any code dependency. You can minimize, maximize/restore and close the form at runtime
Optional step: To add a help icon in the form control box, go to the properties of Bunifu Form Control Box and set the HelpBox property with a true value.

Adding Bunifu Form Control Box at Run Time

To add a Bunifu Form Control Box to our form at run-time, use the Load event of your form to run the following code:-
C#
VB.NET
private void Form1_Load(object sender, EventArgs e)
{
BunifuFormControlBox controlBox = new BunifuFormControlBox();
/*
* the location of the control depends on your form size
* so depending on your form size setting ensure the control is at the top
* corner of the form
*/
controlBox.Location = new Point(627, 2);
this.Controls.Add(controlBox);
}
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim controlBox As New BunifuFormControlBox()
'
' * the location of the control depends on your form size
' * so depending on your form size setting ensure the control is at the top
' * corner of the form
'
controlBox.Location = New Point(627, 2)
Me.Controls.Add(controlBox)
End Sub
Let's take a deep dive and get insights into the available properties on Bunifu Form Control Box

Properties

The below buttons and their properties control the appearance of Bunifu Form Control Box:

Minimize Caption Button

The Minimize button looks like a minus sign on the control box. Clicking on the Minimize Button places the Window Form on the taskbar, usually found at the bottom of the screen. Below are option properties found in the minimize button:

1. BackColor

This property gets or sets the background color of the minimize button. It accepts the use of both the HEX and RGB color formats.

2. BorderRadius

This property gets or sets a radius value (integer) that determines the roundness of the Minimize Button edges. The greater the value, the more rounded the border corners become.

3. Enabled

This property gets or sets a boolean value that determines whether the minimize button performs an action on the Windows form when you click it. A false value prevents the Minimize button from performing its action on the Windows form, while a true value allows the button to execute an action on the form (e.g., hiding the windows form on the taskbar).

4. EnableDefaultAction

This property gets or sets a boolean value that determines whether the Minimize button performs the default action of hiding the Windows form when you click it. A false value disables the action of hiding the Windows form (i.e., placing the Windows form in the taskbar), while a true value enables hiding the form which is its default action.
If you have disabled the default action, you can use the MinimizeCaption property and access the click event as described in following code:
C#
VB.NET
private void Form1_Load(object sender, EventArgs e)
{
bunifuFormControlBox1.MinimizeCaption.Click += MinimizeCaption_Click;
}
private void MinimizeCaption_Click(object? sender, EventArgs e)
{
//Your minimize action
DialogResult result = MessageBox.Show("You are hiding your form, do you wish to proceed?", "Hide Form", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
this.WindowState = FormWindowState.Minimized;
}
}
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
AddHandler bunifuFormControlBox1.MinimizeCaption.Click, AddressOf MinimizeCaption_Click
End Sub
Private Sub MinimizeCaption_Click(ByVal sender As Object, ByVal e As EventArgs)
'Your minimize action
Dim result As DialogResult = MessageBox.Show("You are hiding your form, do you wish to proceed?", "Hide Form", MessageBoxButtons.YesNo)
If result = DialogResult.Yes Then
Me.WindowState = FormWindowState.Minimized
End If
End Sub

Result

5. HoverColor

This property gets or sets the back color of the minimize button whenever the mouse hovers over the minimize box. It accepts the use of both the HEX and RGB color formats.

6. Icon

This property gets or sets the image that will be used as the graphical representation for the minimize box. A suitable icon would be the minus sign. To specify an image for the minimize box, click on the ellipsis button located on the value of this property, which will bring up an options dialog box where you can select the desired image.

7. IconAlt

This property gets or sets an alternative image of the current icon to be used as the alternative representation for the minimize box when the form has a different WindowState.
This property is not suitable for the Minimize, Help and Close caption buttons. However for your creativity, you can specify an alternative icon other than the default minus, help, and close caption buttons.

8. IconColor

This property gets or sets the color of the icon set on the minimize box. It accepts the use of both the HEX and RGB color formats.

9. IconHoverColor

This property gets or sets the color of the icon set on the minimize box whenever the mouse hovers on the minimize box. It accepts the use of both the HEX and RGB color formats.

10.IconPressedColor

This property gets or sets the color of the icon set on the minimize box whenever the user clicks on the minimize box. It accepts the use of both the HEX and RGB color formats.

11.IconSize

This property gets or sets both the height and width of the icon set on the minimize box. The default value is 14 for both the height and width properties.

12.PressedColor

This property gets or sets the back color on the minimize box whenever the user clicks on the minimize box. It accepts the use of both the HEX and RGB color formats.

13.MinimizeBox

This property gets or sets a boolean value that determines if the minimize button is visible. A false value hides the minimize button whereas a true value shows the minimize button

Maximize/Restore Caption Button

The Maximize/Restore button is in the middle and has two states. When you click on the button, it enlarges the window to occupy the entire screen, and you can restore a window, which reduces the window to the size it was before being maximized. Below are option properties found in the Maximize button:

1. BackColor

This property gets or sets the background color of the maximize button. It accepts the use of both the HEX and RGB color formats.

2. BorderRadius

This property gets or sets a radius value (integer) that determines the roundness of the Maximize Button edges. The greater the value, the more rounded the border corners become.

3. Enabled

This property gets or sets a boolean value that determines whether the Maximize button performs an action on the Windows form when you click it. A false value prevents the Maximize button from performing its action on the Windows form, while a true value allows the button to execute an action on the form (for example, enlarging the Windows form on the user screen to its full size).

4. EnableDefaultAction

This property gets or sets a boolean value that determines whether the maximize button performs the default action of enlarging/restoring the Windows form when you click it. A false value disables the action (if you want to perform other functions with it) while a true value enables the default action.
If you have disabled the default action, you can use the MaximizeCaption property and access the click event as described in following code:
C#
Second Tab
private void Form3_Load(object sender, EventArgs e)
{
bunifuFormControlBox1.MaximizeCaption.Click += MaximizeCaption_Click;
}
private void MaximizeCaption_Click(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Maximized)
{
DialogResult result = MessageBox.Show("You are restoring your form, do you wish to proceed?", "Restore Form", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
this.WindowState = FormWindowState.Normal;
}
}
else
{
DialogResult result = MessageBox.Show("You are maximizing your form, do you wish to proceed?", "Maximize Form", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
Rectangle workingArea = Screen.GetWorkingArea(this);
this.MaximizedBounds = workingArea;
this.WindowState = FormWindowState.Maximized;
}
}
}
Private Sub Form3_Load(ByVal sender As Object, ByVal e As EventArgs)
AddHandler bunifuFormControlBox1.MaximizeCaption.Click, AddressOf MaximizeCaption_Click
End Sub
Private Sub MaximizeCaption_Click(ByVal sender As Object, ByVal e As EventArgs)
If WindowState = FormWindowState.Maximized Then
Dim result As DialogResult = MessageBox.Show("You are restoring your form, do you wish to proceed?", "Restore Form", MessageBoxButtons.YesNo)
If result = DialogResult.Yes Then
Me.WindowState = FormWindowState.Normal
End If
Else
Dim result As DialogResult = MessageBox.Show("You are maximizing your form, do you wish to proceed?", "Maximize Form", MessageBoxButtons.YesNo)
If result = DialogResult.Yes Then
Dim workingArea As Rectangle = Screen.GetWorkingArea(Me)
Me.MaximizedBounds = workingArea
Me.WindowState = FormWindowState.Maximized
End If
End If
End Sub

5. HoverColor

This property gets or sets the back color of the maximize button whenever the mouse hovers over the maximize box. It accepts the use of both the HEX and RGB color formats.

6. Icon

This property gets or sets the image that will be used as the graphical representation for the maximize box. A suitable icon would be the minus sign. To specify an image for the maximize box, click on the ellipsis button located on the value of this property, which will bring up an options dialog box where you can select the desired image.

7. IconAlt

This property gets or sets an alternative image of the current icon to be used as the alternative representation for the maximize box. When the Windows form is maximized to its full size, the alternate icon is displayed.
A suitable alternative icon could be a restore icon which by default is set on the property.

8. IconColor

This property gets or sets a color overlay on the icon set on the maximize box. It accepts the use of both the HEX and RGB color formats.

9. IconHoverColor

This property gets or sets the color of the icon set on the maximize box whenever the mouse hovers on the maximize button. It accepts the use of both the HEX and RGB color formats.

10.IconPressedColor

This property gets or sets the color of the icon set on the maximize box whenever the user clicks on the maximize box. It accepts the use of both the HEX and RGB color formats.

11.IconSize

This property gets or sets both the height and width of the icon set on the maximize box. The default value is 14 for both the height and width properties.

12.PressedColor

This property gets or sets the back color on the maximize box whenever the user clicks on the maximize box. It accepts the use of both the HEX and RGB color formats.

13.MaximizeBox

This property gets or sets a boolean value that determines if the maximize button is visible. A false value hides the maximize button whereas a true

Close Caption Button

The Close button is the one on the right with the X. Clicking the Close button will close the window or program. Below are option properties found in the close button:

1. BackColor

This property gets or sets the background color of the close button. It accepts the use of both the HEX and RGB color formats.

2. BorderRadius

This property gets or sets a radius value (integer) that determines the roundness of the close button edges. The greater the value, the more rounded the border corners become.

3. Enabled

This property gets or sets a boolean value that determines whether the close button performs an action on the Windows form when you click it. A false value prevents the close button from performing its action on the Windows form, while a true value allows the button to execute an action on the form (e.g., closing the windows form).

4. EnableDefaultAction

This property gets or sets a boolean value that determines whether the close button performs the default action of closing the Windows form when you click it. A false value disables the action of closing so that you can define your own action, while a true value allows the form to close, which is the default action.
To define your own action, you can use the CloseCaption property and access the click event as described in the following code:
C#
VB.NET
private void Form1_Load(object sender, EventArgs e)
{
bunifuFormControlBox1.CloseCaption.Click += CloseCaption_Click;
}
private void CloseCaption_Click(object? sender, EventArgs e)
{
DialogResult result = MessageBox.Show("You are closing your form, do you wish to proceed?", "Close Form", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
this.Close();
}
}
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
AddHandler bunifuFormControlBox1.CloseCaption.Click, AddressOf CloseCaption_Click
End Sub
Private Sub CloseCaption_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim result As DialogResult = MessageBox.Show("You are closing your form, do you wish to proceed?", "Close Form", MessageBoxButtons.YesNo)
If result = DialogResult.Yes Then
Me.Close()
End If
End Sub

5. HoverColor

This property gets or sets the back color of the close button whenever the mouse hovers over the close box. It accepts the use of both the HEX and RGB color formats.

6. Icon

This property gets or sets the image that will be used as the graphical representation for the close box. A suitable icon would be the X sign. To specify an image for the close box, click on the ellipsis button located on the value of this property, which will bring up an options dialog box where you can select the desired image.

7. IconAlt

This property gets or sets an alternative image of the current icon to be used as the alternative representation for the close box. The current window state will show the image set on the Icon property and another window state would show the alternate icon set in this IconAlt property.
This property is not suitable for the Close button. However, for your creativity you can specify an alternative icon other than the default X symbol for the close button.

8. IconColor

This property gets or sets the color of the icon set on the close box. It accepts the use of both the HEX and RGB color formats.

9. IconHoverColor

This property gets or sets the color of the icon set on the close box whenever the mouse hovers on the close box. It accepts the use of both the HEX and RGB color formats.

10.IconPressedColor

This property gets or sets the color of the icon set on the close box whenever the user clicks on the close box. It accepts the use of both the HEX and RGB color formats.

11.IconSize

This property gets or sets both the height and width of the icon set on the close box. The default value is 14 for both the height and width properties.

12.PressedColor

This property gets or sets the back color on the close box whenever the user clicks on the close box. It accepts the use of both the HEX and RGB color formats.

Help Caption Button

The Help button is the one on the first controls on the box. Clicking the Help button runs a process that can open a link to a browser or other window with your help resources. By default, the Help Button is not shown. Set the HelpBox property to true to display a Help button in the form's caption bar. Below you can find the options of the Help button:

1. BackColor

This property gets or sets the background color of the help button. It accepts the use of both the HEX and RGB color formats.

2. BorderRadius

This property gets or sets a radius value (integer) that determines the roundness of the help button edges. The greater the value, the more rounded the border corners become.

3. Enabled

This property gets or sets a boolean value that determines whether the help button performs an action on the Windows form when you click it. A false value prevents the help button from performing its action on the Windows form, while a true value allows the button to execute an action on the form (e.g., open a link to a browser ).
You can define an action by describing it in the helpCaption click event as in the following example:-
C#
VB.NET
private void Form1_Load(object sender, EventArgs e)
{
bunifuFormControlBox1.HelpCaption.Click += HelpCaption_Click;
}
private void HelpCaption_Click(object? sender, EventArgs e)
{
string defaultBrowserPath = GetDefaultBrowserPath();
Process.Start(defaultBrowserPath, "https://docs2.bunifuframework.com/docs/ui/controls");
}
//get the default browser in windows
private string GetDefaultBrowserPath()
{
//get the default browser from windows
string userChoice = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice", "ProgId", null);
string browserPath = (string)Registry.GetValue(@"HKEY_CLASSES_ROOT\" + userChoice + @"\shell\open\command", null, null);
browserPath = browserPath.Replace("\"", "");
browserPath = browserPath.Substring(0, browserPath.LastIndexOf(".exe") + 4);
return browserPath;
}
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
AddHandler bunifuFormControlBox1.HelpCaption.Click, AddressOf HelpCaption_Click
End Sub
Private Sub HelpCaption_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim defaultBrowserPath As String = GetDefaultBrowserPath()
Process.Start(defaultBrowserPath, "https://docs2.bunifuframework.com/docs/ui/controls")
End Sub
'get the default browser in windows
Private Function GetDefaultBrowserPath() As String
'get the default browser from windows
Dim userChoice As String = CStr(Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice", "ProgId", Nothing))
Dim browserPath As String = CStr(Registry.GetValue("HKEY_CLASSES_ROOT\" & userChoice & "\shell\open\command", Nothing, Nothing))
browserPath = browserPath.Replace("""", "")
browserPath = browserPath.Substring(0, browserPath.LastIndexOf(".exe") + 4)
Return browserPath
End Function

5. HoverColor

This property gets or sets the back color of the help button whenever the mouse hovers over the help box. It accepts the use of both the HEX and RGB color formats.

6. Icon

This property gets or sets the image that will be used as the icon vector for the help box. A suitable icon would be the a question mark symbol sign. To specify an image for the help box, click on the ellipsis button located on the value of this property, which will bring up an options dialog box where you can select the desired image.

7. IconAlt

This property gets or sets an alternative image of the current icon to be used as the alternative representation for the help caption.

8. IconColor

This property gets or sets the color of the icon set on the help box. It accepts the use of both the HEX and RGB color formats.

9. IconHoverColor

This property gets or sets the color of the icon set on the help box whenever the mouse hovers on the help box. It accepts the use of both the HEX and RGB color formats.

10.IconPressedColor

This property gets or sets the color of the icon set on the help caption whenever the user clicks on the help caption. It accepts the use of both the HEX and RGB color formats.

11.IconSize

This property gets or sets both the height and width of the icon set on the help caption. The default value is 14 for both the height and width properties.

12.PressedColor

This property gets or sets the back color on the help caption whenever the user clicks on the help caption. It accepts the use of both the HEX and RGB color formats.

13.HelpBox

This property gets or sets a boolean value that determines if the help button is visible. A false value hides the help button whereas a true one shows the help button.

Copy link
On this page
Overview
Getting started
Adding Bunifu Form Control Box at Design Time
Adding Bunifu Form Control Box at Run Time
Properties
Minimize Caption Button
Maximize/Restore Caption Button
Close Caption Button
Help Caption Button