-
Notifications
You must be signed in to change notification settings - Fork 27
Usage Code Example
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;###Find & Replace Dialog
The following declares an instance of FindReplace globablly with reference to a ScintillaNET control.
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);
}
private void FindButton_Click(object sender, EventArgs e)
{
MyGoTo.ShowFind();
}
private void ReplaceButton_Click(object sender, EventArgs e)
{
MyGoTo.ShowReplace();
}
}###Go To Dialog The following creates and shows a Go To dialog. Once the user enters a line number, the referenced ScintillaNET control will go to that location, the form will close. The Go To instance is no longer required.
private void GotoButton_Click(object sender, EventArgs e)
{
GoTo MyGoTo = new GoTo(scintilla1);
MyGoTo.ShowGoToDialog();
}###Incremental Search The Incremental Search control is a component of the FindReplace class and as such, creating an instance of the FindReplace class gives the ability to show the Incremental Search control within the ScintillaNET control (actually infront of it). All that is required is to call the specific method to show the control as below.
MyFindReplace.ShowIncrementalSearch();Optionally the control can be dropped onto a form (in this case named 'incrementalSearcher1' and hooked directly to a FindReplace instance as shown below. In this case, the control is always visible, so a call to 'ShowIncrementalSearch' is not required.
public partial class Form1 : Form
{
// Declare variable for FindReplace dialog
FindReplace MyFindReplace;
public Form1()
{
InitializeComponent();
MyFindReplace = new FindReplace(scintilla1);
incrementalSearcher1.FindReplace = MyFindReplace;
}
}###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 following shortcuts are used:
- CTRL+F - Show Find Dialog
- CTRL+H - Show Replace Dialog
- CTRL+I - Show Incremental Find Control
- CTRL+G - Show Go To Dialog
private void scintilla1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.F)
{
MyFindReplace.ShowFind();
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(scintilla1);
MyGoTo.ShowGoToDialog();
e.SuppressKeyPress = true;
}
}