-
Notifications
You must be signed in to change notification settings - Fork 29
Usage Code Example (Multi Scintilla)
Steve Towner edited this page Aug 10, 2018
·
8 revisions
Here is an example how to integrate multiple ScintillaNET controls (for example a multi-document text editor). 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 events
scintilla1.KeyDown += genericScintilla_KeyDown;
scintilla2.KeyDown += genericScintilla_KeyDown;
scintilla1.Enter += genericScintilla_Enter;
scintilla2.Enter += genericScintilla_Enter;
}
private void FindButton_Click(object sender, System.Windows.Forms.EventArgs e)
{
MyGoTo.ShowFind();
}
private void ReplaceButton_Click(object sender, System.Windows.Forms.EventArgs e)
{
MyGoTo.ShowReplace();
}
}
###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 genericScintilla_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((Scintilla)sender);
MyGoTo.ShowGoToDialog();
e.SuppressKeyPress = true;
}
}
private void genericScintilla_Enter(object sender, System.Windows.Forms.EventArgs e)
{
myFindReplace.Scintilla = (Scintilla)sender;
}
private void MyFindReplace_KeyPressed(object sender, System.Windows.Forms.KeyEventArgs e)
{
genericScintilla_KeyDown(sender, e);
}