HypernovaDesktop Components · docs
Binarymission
WinForms › Office Window

Office Window

.NET Framework 4.8.NET 6 / 8 / 10v5.0.0WinForms

A Windows Forms window that draws its own title bar and border – in an Office, Visual Studio or Windows 8 style, or in your own colours – while keeping everything a standard window does: moving, resizing from every edge, the minimise, maximise and close buttons, and – with ShouldEnableWindowsKeyHooks – the Windows-key snapping shortcuts.

14public types
216public members
1namespaces

Assembly

AssemblyBinarymission.WinForms.Controls.ModernChromeWindow.dll
Root namespaceBinarymission.WinForms.Controls.Windows
Target frameworks.NET Framework 4.8, .NET 6 / 8 / 10

Overview

Using it

Derive your form from ModernChromeWindow instead of Form. Add controls to it as usual; the title bar and border sit outside the client area, so docking and anchoring work against the content area. Control.Text or TitlebarText is the caption, and Form.Icon is drawn at its left.

Themes

WindowChromeTheme picks one of the built-in looks; the default is WindowChromeTheme.OfficeBlack. Choosing a built-in theme sets the chrome colours, every command button's brushes and colours, and Control.BackColor, replacing any you had set. To use your own colours, set WindowChromeTheme to WindowChromeTheme.Custom first, then WindowChromeStartColor, WindowChromeEndColor, WindowChromeBorderColor and the command button properties. To draw the chrome entirely yourself, set ModernWindowChromeProvider.

Size of the frame

ChromeTitlebarHeight (32 by default) and ChromeBorderSize (8) are in logical pixels and scale with the display. Changing either grows or shrinks the window by the same amount, so the client area keeps its size, unless ShouldAutoResizeWindowHeightOnTitlebarHeightChange or ShouldAutoResizeWindowSizeOnBorderWidthChange is turned off.

The command buttons

Minimise, maximise/restore and close work by themselves. Handle WindowMinimizeRequested, WindowRestoreOrMaximizeRequested or WindowCloseRequested to take over a button: while the event has a handler the window no longer acts on that button itself – call Form.Close or set Form.WindowState in the handler. IsControlBoxEnabled greys all three out.

A window without a title bar

IsFullChromeDisabled keeps only the border – for a splash screen or a tool window that can still be moved and resized – and puts the title bar back as it was when turned off again.

Getting started

A main window in the Visual Studio dark style, which asks before closing.

using System.Windows.Forms;
using Binarymission.WinForms.Controls.Windows;

public sealed class MainWindow : ModernChromeWindow
{
    public MainWindow()
    {
        Text = "Order Manager";
        WindowChromeTheme = WindowChromeTheme.VisualStudioDark;
        ChromeTitlebarHeight = 36;

        WindowCloseRequested += (sender, e) =>
        {
            if (MessageBox.Show(this, "Close Order Manager?", Text, MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                Close();
            }
        };

        Controls.Add(new DataGridView { Dock = DockStyle.Fill });
    }
}

API reference

Binarymission.WinForms.Controls.Windows

class BrushContainerHolds a brush for a ModernChromeWindow property, so the designer can set a plain colour while code can set any brush, such as a gradient.
interface IModernChromeHostWindowThe interface IModernChromeHostWindow specifies some special data and behaviour for the chrome window.
interface IModernWindowChromeProviderSpecifies the methods to be implemented by a custom Window chrome rendering provider.
class ModernChromeWindowA Windows Forms window that draws its own title bar and border - in an Office, Visual Studio or Windows 8 style, or in your own colours - while keeping everything a standard window does: moving, resizing from every edge, the minimise, maximise and close buttons, and - with ShouldEnableWindowsKeyHooks - the Windows-key snapping shortcuts.
enum DesktopDockModeWhere the window sits on its screen: docked to an edge, maximised, minimised, or floating.
enum MouseClickTypeWhich mouse button clicked the window icon.
class WindowChromeBorderSizeChangedEventArgsOld and new border sizes of a ModernChromeWindow.
enum WindowChromeThemeThe built-in looks of a ModernChromeWindow's title bar, border and command buttons.
class WindowChromeThemeChangedEventArgsProvides data for WindowChromeThemeChanged: the theme before and after.
class WindowChromeTitlebarHeightChangedEventArgsProvides data for WindowChromeTitlebarHeightChanged and WindowChromeBorderSizeChanged: the size before and after.
class WindowEdgeCornerRadiusHow far the corners of a ModernChromeWindow are rounded, while ShouldDrawWindowEdgesWithRoundedCorners is on.
class WindowIconClickEventArgsProvides data for WindowIconClicked.
class WindowStateChangedEventArgsProvides data for WindowStateChanged: the window state before and after.
enum WindowStyleWhether the window's caption area and its content are drawn as one merged band or as two separate ones.