PostItNote
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
- Title bar. The built-in title bar (
IsDefaultTitlebarVisible) is 28 logical pixels tall, with a command icon at the left (PostItNoteCommandBarInvokeRequested), a close icon at the right (PostItNoteCloseRequested) and an optionalPinin the middle. Turn it off for a thin 8-pixel strip instead, or supply your own withTitlebar. Any of them drags the note. - Text area. A rich text box holding
NoteText, inDefaultInputTextBoxFont. Hide it withIsDefaultInputTextBoxVisibleto put controls of your own on the note. - Status bar. One line of
StatusbarTextalong the bottom (IsStatusBarVisible), beside a gripper that resizes the 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 | |
|---|---|
PostItNote | 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. |
| Properties | |
BasicTitlebarGradientEndColor | Gets or sets the colour the thin top strip fades to, while the built-in title bar is hidden. |
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. |
BasicTitlebarLinearGradientMode | Gets or sets the direction of the thin top strip's gradient. |
CreateParams | Gets the window creation settings, adding the drop shadow the note casts. |
DefaultInputTextBoxFont | Gets or sets the font of the note's text area. |
DefaultInputTextBoxForecolor | Gets or sets the colour of the text in the note's text area. |
DefaultTitlebarBrushEndColor | Gets or sets the colour the built-in title bar fades to, at its bottom right. |
DefaultTitlebarBrushStartColor | Gets or sets the colour at the start of the built-in title bar's gradient. |
DefaultTitlebarLinearGradientMode | Gets or sets a gradient direction for the built-in title bar. |
FollowsParentWindow | Gets or sets whether the note hides and returns with the window it was given in its constructor. |
InactiveOpacity | Gets or sets how opaque the note is while another window has the focus. |
IsAlwaysOnTop | Gets or sets whether the note stays above the other windows on the desktop. |
IsBasicTitlebarBackgroundGradient | Gets or sets whether the thin top strip is a gradient or a solid colour. |
IsDefaultInputTextBoxVisible | Gets or sets whether the note shows its built-in text area. |
IsDefaultTitlebarBackgroundGradient | Gets or sets whether the built-in title bar is a gradient or a solid colour. |
IsDefaultTitlebarVisible | Gets or sets whether the note shows its built-in title bar, with the command icon, pin and close icon. |
IsStatusBarVisible | Gets or sets whether the note shows its status bar along the bottom. |
NoteText | Gets or sets the text put in the note's text area. |
NoteTheme | Gets or sets the colour scheme of the note: its background and both title bars. |
Pin | Gets or sets the coloured pin shown in the middle of the built-in title bar. |
StatusbarForeColor | Gets or sets the colour of the status bar text. |
StatusbarText | Gets or sets the line of text in the status bar along the bottom of the note. |
StatusbarTooltip | Gets or sets the tool tip shown when the pointer rests on the status bar. |
Titlebar | Gets or sets a title bar of your own, in place of the built-in one. |
TitlebarBrush | Gets or sets the brush that paints the built-in title bar, in place of its two-colour gradient. |
TitlebarTooltip | Gets or sets the tool tip shown when the pointer rests on the built-in title bar. |
| Methods | |
Dispose | Releases the note's brushes, fonts and tool tips, and stops following its window. |
OnActivated | Raises the Form.Activated event and brings the note to full opacity. |
OnBackColorChanged | Raises the Control.BackColorChanged event and gives the text area the same background. |
OnDeactivate | Raises the Form.Deactivate event and fades the note to InactiveOpacity. |
OnFormClosing | Raises the Form.FormClosing event. |
OnMouseDoubleClick | Raises the Control.MouseDoubleClick event. |
OnMouseDown | Raises the Control.MouseDown event, and starts a move when the title bar strip is pressed. |
OnMouseMove | Raises the Control.MouseMove event and shows the move cursor over the title bar strip. |
OnMouseUp | Raises the Control.MouseUp event, and raises the right-click events of the title bar strip. |
OnPaint | Raises the Control.Paint event after drawing the note's background, title bar and gripper. |
WndProc | Processes Windows messages: lays the note out when it is resized, and lets the gripper in the bottom corner resize it. |
| Events | |
PostItNoteCloseRequested | Occurs when the user clicks the close icon on the built-in title bar. |
PostItNoteCommandBarInvokeRequested | Occurs when the user clicks the command icon at the left of the built-in title bar. |
PostiItNoteBasicTitlebarDoubleClicked | Occurs when the user double-clicks the thin strip shown across the top while the built-in title bar is hidden. |
PostiItNoteBasicTitlebarRightClicked | Occurs when the user right-clicks the thin strip shown across the top while the built-in title bar is hidden. |
PostiItNoteDefaultTitlebarDoubleClicked | Occurs when the user double-clicks the built-in title bar with the left button. |
PostiItNoteDefaultTitlebarRightClicked | Occurs when the user right-clicks the built-in title bar. |
Constructors
PostItNote
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
FollowsParentWindowis on, the note hides and returns with it. May benullfor 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
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
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
Gets or sets the direction of the thin top strip's gradient.
- Value
- One of the
LinearGradientModevalues. The default isHorizontal, 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
Gets the window creation settings, adding the drop shadow the note casts.
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
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
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
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
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
Gets or sets whether the note hides and returns with the window it was given in its constructor.
- Value
trueto follow the window; the default istrue.
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
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
Gets or sets whether the note stays above the other windows on the desktop.
- Value
trueto keep it on top; the default istrue, 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
Gets or sets whether the thin top strip is a gradient or a solid colour.
- Value
trueto fade fromBasicTitlebarGradientStartColortoBasicTitlebarGradientEndColor;falsefor a solidBasicTitlebarGradientStartColor. The default istrue.
Remarks
Setting it also applies any change to the strip's colours straight away.
IsDefaultInputTextBoxVisible
Gets or sets whether the note shows its built-in text area.
- Value
trueto show the text area; the default istrue.
Remarks
Hide it to fill the note with controls of your own, such as a checklist or a date picker.
IsDefaultTitlebarBackgroundGradient
Gets or sets whether the built-in title bar is a gradient or a solid colour.
- Value
falseby 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
Gets or sets whether the note shows its built-in title bar, with the command icon, pin and close icon.
- Value
truefor the built-in title bar;falsefor a thin 8-pixel strip in theBasicTitlebarGradientStartColorcolours. The default istrue.
Remarks
The text area moves up or down to fit. Setting Titlebar turns this off.
IsStatusBarVisible
Gets or sets whether the note shows its status bar along the bottom.
- Value
trueto show the status bar; the default istrue.
Remarks
Without it the text area runs down to the resize gripper.
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
Gets or sets the colour scheme of the note: its background and both title bars.
- Value
- One of the
PostItNoteThemevalues. The default isPostItNoteTheme.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
Gets or sets the coloured pin shown in the middle of the built-in title bar.
- Value
- One of the
PostItNotePinvalues. The default isPostItNotePin.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
Gets or sets the colour of the status bar text.
- Value
- The text colour. The default is
Color.Empty, which uses the note'sControl.ForeColor.
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
Gets or sets the tool tip shown when the pointer rests on the status bar.
- Value
- The tip text, or
nullfor none. The default isnull.
Remarks
Handy for the full text of a status line too long to fit.
Titlebar
Gets or sets a title bar of your own, in place of the built-in one.
- Value
- Your title bar, or
nullfor the built-in one. The default isnull.
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
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
DefaultTitlebarBrushStartColorandDefaultTitlebarBrushEndColor.
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
Gets or sets the tool tip shown when the pointer rests on the built-in title bar.
- Value
- The tip text, or
nullfor none. The default isnull.
Remarks
Useful for saying what the note is about, or that it can be dragged.
Methods
Dispose
Releases the note's brushes, fonts and tool tips, and stops following its window.
Parameters
disposingtruewhen called fromDispose();falsewhen called from a finaliser.
Remarks
A brush or font you supplied through TitlebarBrush or
DefaultInputTextBoxFont is not disposed.
OnActivated
Raises the Form.Activated event and brings the note to full opacity.
Parameters
e- The event data.
See also
OnBackColorChanged
Raises the Control.BackColorChanged event and gives the text area the same background.
Parameters
e- The event data.
OnDeactivate
Raises the Form.Deactivate event and fades the note to InactiveOpacity.
Parameters
e- The event data.
OnFormClosing
Raises the Form.FormClosing event.
Parameters
e- The event data; set
Cancelto keep the note open.
OnMouseDoubleClick
Raises the Control.MouseDoubleClick event.
Parameters
e- The event data.
OnMouseDown
Raises the Control.MouseDown event, and starts a move when the title bar strip is pressed.
Parameters
e- The event data.
OnMouseMove
Raises the Control.MouseMove event and shows the move cursor over the title bar strip.
Parameters
e- The event data.
OnMouseUp
Raises the Control.MouseUp event, and raises the right-click events of the title bar strip.
Parameters
e- The event data.
OnPaint
Raises the Control.Paint event after drawing the note's background, title bar and gripper.
Parameters
e- The event data.
WndProc
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
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
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
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
Occurs when the user right-clicks the thin strip shown across the top while the built-in title bar is hidden.
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
Occurs when the user right-clicks the built-in title bar.