HypernovaDesktop Components · docs
Binarymission
WinForms › Post It Note › PostItNote

PostItNote

class.NET 6 / 8 / 10.NET Framework 4.8Binarymission.WinForms.Controls.Containers

A sticky note for the desktop: a small, borderless, always-on-top window with a coloured title bar, a text area the user can type in, and a status bar – for reminders, comments on a record, or notes beside a document.

public partial class PostItNote : Form

Inherits from / implements: Form

Remarks

A note is a Form of its own. Create it in code with the window it belongs to, set its text and look, and call Form.Show. It has no parameterless constructor, so it is not dropped on a designer surface.

The parts of a note

Behaviour

The close icon does not close the note: it raises PostItNoteCloseRequested, and your handler decides – confirm, then call Form.Close. While FollowsParentWindow is on, the note hides when its window is minimised or hidden and comes back with it. InactiveOpacity fades notes that are not being worked in.

Appearance

NoteTheme sets the background and both title bars' colours in one go; set it first, then adjust single colours. A new note starts with sample text in the text area and status bar – replace both.

Examples

A reminder note beside a customer record, removed when the user confirms its close icon.

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

private void OnAddNoteClick(object sender, EventArgs e)
{
    PostItNote note = new PostItNote(this)
    {
        NoteTheme = PostItNoteTheme.Blue,
        Pin = PostItNotePin.Red,
        NoteText = "Call back about the overdue invoice INV-20431.",
        StatusbarText = "Added " + DateTime.Now.ToString("d MMM, HH:mm"),
        TitlebarTooltip = "Drag to move",
        InactiveOpacity = 0.85,
        Size = new Size(240, 200),
        StartPosition = FormStartPosition.Manual,
        Location = new Point(Right - 260, Top + 80)
    };

    note.PostItNoteCloseRequested += (s, args) =>
    {
        if (MessageBox.Show(note, "Remove this note?", "Notes", MessageBoxButtons.YesNo) == DialogResult.Yes)
        {
            note.Close();
        }
    };

    note.Show(this);
}

Members at a glance

Constructors
PostItNoteInitialises a new note belonging to a window: 200 by 200 logical pixels, in the default yellow theme, on top of other windows and centred on the screen.
Properties
BasicTitlebarGradientEndColorGets or sets the colour the thin top strip fades to, while the built-in title bar is hidden.
BasicTitlebarGradientStartColorGets or sets the colour at the start of the thin strip shown across the top while the built-in title bar is hidden.
BasicTitlebarLinearGradientModeGets or sets the direction of the thin top strip's gradient.
CreateParamsGets the window creation settings, adding the drop shadow the note casts.
DefaultInputTextBoxFontGets or sets the font of the note's text area.
DefaultInputTextBoxForecolorGets or sets the colour of the text in the note's text area.
DefaultTitlebarBrushEndColorGets or sets the colour the built-in title bar fades to, at its bottom right.
DefaultTitlebarBrushStartColorGets or sets the colour at the start of the built-in title bar's gradient.
DefaultTitlebarLinearGradientModeGets or sets a gradient direction for the built-in title bar.
FollowsParentWindowGets or sets whether the note hides and returns with the window it was given in its constructor.
InactiveOpacityGets or sets how opaque the note is while another window has the focus.
IsAlwaysOnTopGets or sets whether the note stays above the other windows on the desktop.
IsBasicTitlebarBackgroundGradientGets or sets whether the thin top strip is a gradient or a solid colour.
IsDefaultInputTextBoxVisibleGets or sets whether the note shows its built-in text area.
IsDefaultTitlebarBackgroundGradientGets or sets whether the built-in title bar is a gradient or a solid colour.
IsDefaultTitlebarVisibleGets or sets whether the note shows its built-in title bar, with the command icon, pin and close icon.
IsStatusBarVisibleGets or sets whether the note shows its status bar along the bottom.
NoteTextGets or sets the text put in the note's text area.
NoteThemeGets or sets the colour scheme of the note: its background and both title bars.
PinGets or sets the coloured pin shown in the middle of the built-in title bar.
StatusbarForeColorGets or sets the colour of the status bar text.
StatusbarTextGets or sets the line of text in the status bar along the bottom of the note.
StatusbarTooltipGets or sets the tool tip shown when the pointer rests on the status bar.
TitlebarGets or sets a title bar of your own, in place of the built-in one.
TitlebarBrushGets or sets the brush that paints the built-in title bar, in place of its two-colour gradient.
TitlebarTooltipGets or sets the tool tip shown when the pointer rests on the built-in title bar.
Methods
DisposeReleases the note's brushes, fonts and tool tips, and stops following its window.
OnActivatedRaises the Form.Activated event and brings the note to full opacity.
OnBackColorChangedRaises the Control.BackColorChanged event and gives the text area the same background.
OnDeactivateRaises the Form.Deactivate event and fades the note to InactiveOpacity.
OnFormClosingRaises the Form.FormClosing event.
OnMouseDoubleClickRaises the Control.MouseDoubleClick event.
OnMouseDownRaises the Control.MouseDown event, and starts a move when the title bar strip is pressed.
OnMouseMoveRaises the Control.MouseMove event and shows the move cursor over the title bar strip.
OnMouseUpRaises the Control.MouseUp event, and raises the right-click events of the title bar strip.
OnPaintRaises the Control.Paint event after drawing the note's background, title bar and gripper.
WndProcProcesses Windows messages: lays the note out when it is resized, and lets the gripper in the bottom corner resize it.
Events
PostItNoteCloseRequestedOccurs when the user clicks the close icon on the built-in title bar.
PostItNoteCommandBarInvokeRequestedOccurs when the user clicks the command icon at the left of the built-in title bar.
PostiItNoteBasicTitlebarDoubleClickedOccurs when the user double-clicks the thin strip shown across the top while the built-in title bar is hidden.
PostiItNoteBasicTitlebarRightClickedOccurs when the user right-clicks the thin strip shown across the top while the built-in title bar is hidden.
PostiItNoteDefaultTitlebarDoubleClickedOccurs when the user double-clicks the built-in title bar with the left button.
PostiItNoteDefaultTitlebarRightClickedOccurs when the user right-clicks the built-in title bar.

Constructors

PostItNote

public PostItNote(Form parentWindow) : base()

Initialises a new note belonging to a window: 200 by 200 logical pixels, in the default yellow theme, on top of other windows and centred on the screen.

Parameters
parentWindow
The window the note belongs to. While FollowsParentWindow is on, the note hides and returns with it. May be null for a note that belongs to no window.
Remarks

The note starts with sample text in its text area and status bar; set NoteText and StatusbarText.

Properties

BasicTitlebarGradientEndColor

public Color BasicTitlebarGradientEndColor

Gets or sets the colour the thin top strip fades to, while the built-in title bar is hidden.

Value
The strip's end colour. Every built-in theme sets Color.White.
Remarks

Used only while IsBasicTitlebarBackgroundGradient is on. Set it before the note is shown; on a note already on screen the change appears the next time the note is resized.

BasicTitlebarGradientStartColor

public Color BasicTitlebarGradientStartColor

Gets or sets the colour at the start of the thin strip shown across the top while the built-in title bar is hidden.

Value
The strip's start colour. The default theme sets Color.Tomato.
Remarks

Set it before the note is shown; on a note already on screen the change appears the next time the note is resized. NoteTheme overwrites it.

See also

BasicTitlebarLinearGradientMode

public LinearGradientMode BasicTitlebarLinearGradientMode

Gets or sets the direction of the thin top strip's gradient.

Value
One of the LinearGradientMode values. The default is Horizontal, left to right.
Remarks

Set it before the note is shown; on a note already on screen the change appears the next time the note is resized.

CreateParams

protected override CreateParams CreateParams

Gets the window creation settings, adding the drop shadow the note casts.

DefaultInputTextBoxFont

public Font DefaultInputTextBoxFont

Gets or sets the font of the note's text area.

Value
The font. The default is the system default font's family at 11 points.
Remarks

The note does not dispose a font you supply, so one shared with other controls is safe to use.

DefaultInputTextBoxForecolor

public Color DefaultInputTextBoxForecolor

Gets or sets the colour of the text in the note's text area.

Value
The text colour. Reading it always returns Color.Empty; the colour set is applied to the text area but not stored.

DefaultTitlebarBrushEndColor

public Color DefaultTitlebarBrushEndColor

Gets or sets the colour the built-in title bar fades to, at its bottom right.

Value
The title bar's end colour. Every built-in theme sets Color.White.
Remarks

Set it before the note is shown; on a note already on screen the change appears the next time the note is resized.

DefaultTitlebarBrushStartColor

public Color DefaultTitlebarBrushStartColor

Gets or sets the colour at the start of the built-in title bar's gradient.

Value
The title bar's start colour, at its top left. The default theme sets Color.LightGreen.
Remarks

Set it before the note is shown; on a note already on screen the change appears the next time the note is resized. NoteTheme overwrites it, and TitlebarBrush replaces the gradient altogether.

See also

DefaultTitlebarLinearGradientMode

public LinearGradientMode DefaultTitlebarLinearGradientMode

Gets or sets a gradient direction for the built-in title bar.

Value
The default is Horizontal.
Remarks

The built-in title bar is always painted with its gradient running from the top left corner to the bottom right, whatever this is set to.

FollowsParentWindow

public bool FollowsParentWindow

Gets or sets whether the note hides and returns with the window it was given in its constructor.

Value
true to follow the window; the default is true.
Remarks

While on, minimising or hiding that window hides the note too, and restoring the window brings back the notes that were showing when it went – so a note never floats over another application. A note your code hid stays hidden. Turn it off to leave the note on screen whatever its window does.

InactiveOpacity

public double InactiveOpacity

Gets or sets how opaque the note is while another window has the focus.

Value
From 0.1 (nearly transparent) to 1 (solid); values outside that range are clamped. The default is 1, which never fades the note.
Remarks

A value such as 0.8 lets a deskful of notes fade back while the user works, and brings a note back to full strength as soon as it is clicked.

IsAlwaysOnTop

public bool IsAlwaysOnTop

Gets or sets whether the note stays above the other windows on the desktop.

Value
true to keep it on top; the default is true, as a sticky note behaves.
Remarks

The same setting as Form.TopMost. Turn it off for a note holding longer text that the reader will want to put behind other windows.

IsBasicTitlebarBackgroundGradient

public bool IsBasicTitlebarBackgroundGradient

Gets or sets whether the thin top strip is a gradient or a solid colour.

Value
true to fade from BasicTitlebarGradientStartColor to BasicTitlebarGradientEndColor; false for a solid BasicTitlebarGradientStartColor. The default is true.
Remarks

Setting it also applies any change to the strip's colours straight away.

IsDefaultInputTextBoxVisible

public bool IsDefaultInputTextBoxVisible

Gets or sets whether the note shows its built-in text area.

Value
true to show the text area; the default is true.
Remarks

Hide it to fill the note with controls of your own, such as a checklist or a date picker.

IsDefaultTitlebarBackgroundGradient

public bool IsDefaultTitlebarBackgroundGradient

Gets or sets whether the built-in title bar is a gradient or a solid colour.

Value
false by default, although the built-in title bar is drawn as a gradient until this is set.
Remarks

Setting it to false paints the title bar in solid DefaultTitlebarBrushStartColor – but only until the note is next resized, when the gradient returns. For a lasting solid title bar, set TitlebarBrush to a SolidBrush.

IsDefaultTitlebarVisible

public bool IsDefaultTitlebarVisible

Gets or sets whether the note shows its built-in title bar, with the command icon, pin and close icon.

Value
true for the built-in title bar; false for a thin 8-pixel strip in the BasicTitlebarGradientStartColor colours. The default is true.
Remarks

The text area moves up or down to fit. Setting Titlebar turns this off.

IsStatusBarVisible

public bool IsStatusBarVisible

Gets or sets whether the note shows its status bar along the bottom.

Value
true to show the status bar; the default is true.
Remarks

Without it the text area runs down to the resize gripper.

NoteText

public string NoteText

Gets or sets the text put in the note's text area.

Value
The text last set. A new note holds "Sample note text!".
Remarks

Setting it replaces what the text area holds. Reading it returns the value last set, not what the user has since typed in the text area.

NoteTheme

public PostItNoteTheme NoteTheme

Gets or sets the colour scheme of the note: its background and both title bars.

Value
One of the PostItNoteTheme values. The default is PostItNoteTheme.Default, a yellow note with a light green title bar.
Remarks

Setting a theme overwrites Control.BackColor, BasicTitlebarGradientStartColor, BasicTitlebarGradientEndColor, DefaultTitlebarBrushStartColor and DefaultTitlebarBrushEndColor, and replaces any TitlebarBrush. Set the theme first and adjust single colours after.

PostItNoteTheme.Custom keeps the colours as they are, for a note coloured entirely by your own settings.

Pin

public PostItNotePin Pin

Gets or sets the coloured pin shown in the middle of the built-in title bar.

Value
One of the PostItNotePin values. The default is PostItNotePin.None.
Remarks

The pin is decoration: it takes no clicks and is not in the tab order. Use it to tell notes apart at a glance – a colour per project, per urgency or per person. It is shown only on the built-in title bar.

StatusbarForeColor

public Color StatusbarForeColor

Gets or sets the colour of the status bar text.

Value
The text colour. The default is Color.Empty, which uses the note's Control.ForeColor.

StatusbarText

public string StatusbarText

Gets or sets the line of text in the status bar along the bottom of the note.

Value
The status text. A new note shows "Status sample text."; replace it, or set it to an empty string for none.
Remarks

Text too long for the bar ends in an ellipsis; give the full text in StatusbarTooltip.

StatusbarTooltip

public string StatusbarTooltip

Gets or sets the tool tip shown when the pointer rests on the status bar.

Value
The tip text, or null for none. The default is null.
Remarks

Handy for the full text of a status line too long to fit.

Titlebar

public UserControl Titlebar

Gets or sets a title bar of your own, in place of the built-in one.

Value
Your title bar, or null for the built-in one. The default is null.
Remarks

The note docks it to the top, gives it the built-in bar's height (28 logical pixels) and a transparent background, turns IsDefaultTitlebarVisible off, and lets the user drag the note by it. It does not add it to the note: add it to the note's Control.Controls yourself.

Setting null brings the built-in title bar back.

Example
UserControl header = new UserControl();
header.Controls.Add(new Label { Text = "Order SO-1182", Dock = DockStyle.Fill, TextAlign = ContentAlignment.MiddleCenter });

note.Titlebar = header;
note.Controls.Add(header);

TitlebarBrush

public Brush TitlebarBrush

Gets or sets the brush that paints the built-in title bar, in place of its two-colour gradient.

Value
The brush the title bar is painted with. By default, a gradient the note makes from DefaultTitlebarBrushStartColor and DefaultTitlebarBrushEndColor.
Remarks

A SolidBrush, TextureBrush or HatchBrush is used as it is. A LinearGradientBrush contributes only its two colours, which are drawn from the top left corner of the title bar to the bottom right.

The note does not dispose a brush you supply. Setting NoteTheme afterwards replaces it with the theme's gradient, so set the theme first.

Example
note.NoteTheme = PostItNoteTheme.Custom;
note.TitlebarBrush = new HatchBrush(HatchStyle.WideUpwardDiagonal, Color.Goldenrod, Color.LemonChiffon);

TitlebarTooltip

public string TitlebarTooltip

Gets or sets the tool tip shown when the pointer rests on the built-in title bar.

Value
The tip text, or null for none. The default is null.
Remarks

Useful for saying what the note is about, or that it can be dragged.

Methods

Dispose

protected override void Dispose(bool disposing)

Releases the note's brushes, fonts and tool tips, and stops following its window.

Parameters
disposing
true when called from Dispose(); false when called from a finaliser.
Remarks

A brush or font you supplied through TitlebarBrush or DefaultInputTextBoxFont is not disposed.

OnActivated

protected override void OnActivated(EventArgs e)

Raises the Form.Activated event and brings the note to full opacity.

Parameters
e
The event data.
See also

OnBackColorChanged

protected override void OnBackColorChanged(EventArgs e)

Raises the Control.BackColorChanged event and gives the text area the same background.

Parameters
e
The event data.

OnDeactivate

protected override void OnDeactivate(EventArgs e)

Raises the Form.Deactivate event and fades the note to InactiveOpacity.

Parameters
e
The event data.

OnFormClosing

protected override void OnFormClosing(FormClosingEventArgs e)

Raises the Form.FormClosing event.

Parameters
e
The event data; set Cancel to keep the note open.

OnMouseDoubleClick

protected override void OnMouseDoubleClick(MouseEventArgs e)

Raises the Control.MouseDoubleClick event.

Parameters
e
The event data.

OnMouseDown

protected override void OnMouseDown(MouseEventArgs e)

Raises the Control.MouseDown event, and starts a move when the title bar strip is pressed.

Parameters
e
The event data.

OnMouseMove

protected override void OnMouseMove(MouseEventArgs e)

Raises the Control.MouseMove event and shows the move cursor over the title bar strip.

Parameters
e
The event data.

OnMouseUp

protected override void OnMouseUp(MouseEventArgs e)

Raises the Control.MouseUp event, and raises the right-click events of the title bar strip.

Parameters
e
The event data.

OnPaint

protected override void OnPaint(PaintEventArgs e)

Raises the Control.Paint event after drawing the note's background, title bar and gripper.

Parameters
e
The event data.

WndProc

protected override void WndProc(ref Message m)

Processes Windows messages: lays the note out when it is resized, and lets the gripper in the bottom corner resize it.

Parameters
m
The message to process.

Events

PostItNoteCloseRequested

public event EventHandler PostItNoteCloseRequested

Occurs when the user clicks the close icon on the built-in title bar.

Remarks

The note stays open: close it from the handler with Form.Close once its text is saved, or keep it open. Not raised while the built-in title bar is hidden.

PostItNoteCommandBarInvokeRequested

public event EventHandler PostItNoteCommandBarInvokeRequested

Occurs when the user clicks the command icon at the left of the built-in title bar.

Remarks

Use it to offer the note's commands – change colour, pin, delete – for example by showing a ContextMenuStrip at the pointer. Not raised while the built-in title bar is hidden.

Example
note.PostItNoteCommandBarInvokeRequested += (s, e) => noteMenu.Show(Cursor.Position);

PostiItNoteBasicTitlebarDoubleClicked

public event EventHandler PostiItNoteBasicTitlebarDoubleClicked

Occurs when the user double-clicks the thin strip shown across the top while the built-in title bar is hidden.

Remarks

A natural place to bring the built-in title bar back by setting IsDefaultTitlebarVisible.

PostiItNoteBasicTitlebarRightClicked

public event EventHandler PostiItNoteBasicTitlebarRightClicked

Occurs when the user right-clicks the thin strip shown across the top while the built-in title bar is hidden.

PostiItNoteDefaultTitlebarDoubleClicked

public event EventHandler PostiItNoteDefaultTitlebarDoubleClicked

Occurs when the user double-clicks the built-in title bar with the left button.

Remarks

For example, collapse the note to its thin strip by setting IsDefaultTitlebarVisible to false.

PostiItNoteDefaultTitlebarRightClicked

public event EventHandler PostiItNoteDefaultTitlebarRightClicked

Occurs when the user right-clicks the built-in title bar.