-
Notifications
You must be signed in to change notification settings - Fork 29
Usage Code Example
Steve Towner edited this page Aug 10, 2018
·
13 revisions
Here are some examples how to integrate with ScintillaNET. For all steps, you will need to:
- Add a reference to the binary output of this project (the .dll).
- Add the following to the top of the file in which you will be using the library:
using ScintillaNET_FindReplaceDialog;
using System.Windows.Forms; // For WPF only
###Find & Replace Dialog
The following declares an instance of FindReplace globablly with reference to a ScintillaNET control.
using ScintillaNET_FindReplaceDialog;
using System.Windows.Forms;
public partial class Form1 : Form
{
// Declare variable for FindReplace dialog
FindReplace MyFindReplace;
public Form1()
{
InitializeComponent();
// Create instance of FindReplace with reference to a ScintillaNET control.
MyFindReplace = new FindReplace(scintilla1); // For WinForms
MyFindReplace = new FindReplace(scintilla1.Scintialla); // For WPF
// Tie in FindReplace event
MyFindReplace.KeyPressed += MyFindReplace_KeyPressed
// Tie in Scintilla event
scintilla1.KeyDown += scintilla1_KeyDown;
}
}
###Keyboard Shortcuts It is handy to unclude keyboard shortcuts normally used in text editors. In the example below, the KeyDown event of a ScintillaNET control is used. If a keypress is used, it is suppressed, preventing ScintillaNET from receiving and displaying the character. The KeyPressed event is also captured. This is generated by the Find and Replace Dialog when it has focus and allows Scintilla to react to key events on the form.
The following shortcuts are used:
- CTRL+F - Show Find Dialog
- F3 - Find Next
- SHIFT+F3 - Find Previous
- CTRL+H - Show Replace Dialog
- CTRL+I - Show Incremental Find Control
- CTRL+G - Show Go To Dialog
using ScintillaNET_FindReplaceDialog;
private void scintilla1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.F)
{
MyFindReplace.ShowFind();
e.SuppressKeyPress = true;
}
else if (e.Shift && e.KeyCode == Keys.F3)
{
MyFindReplace.Window.FindPrevious();
e.SuppressKeyPress = true;
}
else if (e.KeyCode == Keys.F3)
{
MyFindReplace.Window.FindNext();
e.SuppressKeyPress = true;
}
else if (e.Control && e.KeyCode == Keys.H)
{
MyFindReplace.ShowReplace();
e.SuppressKeyPress = true;
}
else if (e.Control && e.KeyCode == Keys.I)
{
MyFindReplace.ShowIncrementalSearch();
e.SuppressKeyPress = true;
}
else if (e.Control && e.KeyCode == Keys.G)
{
GoTo MyGoTo = new GoTo((ScintillaNET.Scintilla)sender);
MyGoTo.ShowGoToDialog();
e.SuppressKeyPress = true;
}
}
private void MyFindReplace_KeyPressed(object sender, System.Windows.Forms.KeyEventArgs e)
{
scintilla1_KeyDown(sender, e);
}