Skip to content

Usage Code Example

Steve Towner edited this page May 15, 2016 · 13 revisions

Here are some examples how to integrate with ScintillaNET. For all steps, you will need to:

  1. Add a reference to the binary output of this project (the .dll).
  2. 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.

using ScintillaNET_FindReplaceDialog;

    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();
		}
	}

###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
using ScintillaNET_FindReplaceDialog;

	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;
		}
	}

Clone this wiki locally