Table of Contents

Class Callbacks

Namespace
Npp.DotNet.Plugin.Winforms
Assembly
Npp.DotNet.Plugin.dll

Various methods that every new form in this app should call.

public static class Callbacks
Inheritance
Callbacks
Inherited Members

Methods

GenericKeyDownHandler(object, KeyEventArgs)

CALL THIS IN YOUR KeyDown HANDLER FOR ALL CONTROLS except TextBoxes
suppress annoying ding when user hits escape, enter, tab, or space

public static void GenericKeyDownHandler(object sender, KeyEventArgs e)

Parameters

sender object
e KeyEventArgs

GenericKeyUpHandler(Form, object, KeyEventArgs, bool)

CALL THIS IN YOUR KeyUp HANDLER FOR ALL CONTROLS (but only add to the form itself IF NOT isModal)
Enter presses button,
escape focuses editor (or closes if isModal),
Ctrl+V pastes text into text boxes and combo boxes
if isModal:

  • tab goes through controls,
  • shift-tab -> go through controls backward
public static void GenericKeyUpHandler(Form form, object sender, KeyEventArgs e, bool isModal)

Parameters

form Form
sender object
e KeyEventArgs
isModal bool

if true, this blocks the parent application until closed. THIS IS ONLY TRUE OF POP-UP DIALOGS

GenericTabNavigationHandler(Form, object, KeyEventArgs)

CALL THIS METHOD IN A KeyUp HANDLER, UNLESS USING GenericKeyUpHandler ABOVE
Tab -> go through controls, Shift+Tab -> go through controls backward.
Ignores invisible or disabled controls.

public static void GenericTabNavigationHandler(Form form, object sender, KeyEventArgs e)

Parameters

form Form

the parent form

sender object

probably a control with a tabstop

e KeyEventArgs

the key event that triggered this

PressEnterInTextBoxHandler(object, bool)

NPPM_MODELESSDIALOG consumes the KeyDown and KeyPress events for the Enter key,
so our KeyUp handler needs to simulate pressing enter to add a new line in a multiline text box.
Note that this does not fully repair the functionality of the Enter key in a multiline text box, because only one newline can be created for a single keypress of Enter, no matter how long the key is held down.

public static void PressEnterInTextBoxHandler(object sender, bool isModal)

Parameters

sender object

the text box that sent the message

isModal bool

if true, this blocks the parent application until closed. THIS IS ONLY TRUE OF POP-UP DIALOGS

RegisterFormIfModeless(Form, bool)

CALL THIS IN YOUR Dispose(bool disposing) METHOD, INSIDE OF THE ".Designer.cs" FILE
When this form is initialized, if it is a modeless dialog (i.e., !isModal; the form does not block the parent application until closed)
this will call Notepad++ with the NPPM_MODELESSDIALOG message to register the form. VERY IMPORTANT: in your Designer.cs files, in the part where it says this.Controls.Add(nameOfControl), you need to make sure the controls are added in tabstop order.
This is because the order in which the controls are added controls tab order.
For example, if you want to go through your controls in the order

  1. FooButton
  2. BarTextBox
  3. BazCheckBox
    You must go to your Designer.cs file and make sure that the Form adds the controls in this order:
this.Controls.Add(this.FooButton);
this.Controls.Add(this.BarTextBox);
this.Controls.Add(this.BazCheckBox);
public static void RegisterFormIfModeless(Form form, bool isModal)

Parameters

form Form
isModal bool

if true, this blocks the parent application until closed. THIS IS ONLY TRUE OF POP-UP DIALOGS

TextBoxKeyPressHandler(object, KeyPressEventArgs)

CALL THIS IN YOUR KeyDown HANDLER FOR ALL TextBoxes and ComboBoxes
suppress annoying ding when user hits tab

public static void TextBoxKeyPressHandler(object sender, KeyPressEventArgs e)

Parameters

sender object
e KeyPressEventArgs

UnregisterFormIfModeless(Form, bool)

CALL THIS IN YOUR Dispose(bool disposing) METHOD, INSIDE OF THE ".Designer.cs" FILE
If this was a modeless dialog (i.e., !isModal; a dialog that does not block Notepad++ while open),
call Notepad++ with the NPPM_MODELESSDIALOG message to unregister the form.

public static void UnregisterFormIfModeless(Form form, bool isModal)

Parameters

form Form
isModal bool

if true, this blocks the parent application until closed. THIS IS ONLY TRUE OF POP-UP DIALOGS