/// <summary> /// Creates a new instance of the AutoCompleteMessageFilter /// </summary> /// <param name="autoCompleteForm">The auto complete form associated with the host rich text box control</param> /// <remarks>The message filter is created and added to the message loop using the install function. The filter /// is automatically disposed once the auto complete form is closed - the filter is automatically removed /// from the message loop at this time.</remarks> private AutoCompleteMessageFilter(frmAutoComplete autoCompleteForm) { AutoCompleteForm = autoCompleteForm; AutoCompleteForm.Disposed += AutoCompleteForm_Disposed; IsDisposed = false; }
private void DoAutoComplete() { // create form if not exists if (_autoCompleteForm == null) { // initialize and wire up new form _autoCompleteForm = new frmAutoComplete(); _autoCompleteForm.AutoCompleteComplete += _autoCompleteForm_AutoCompleteComplete; // install message filter to listen for lost focus AutoCompleteMessageFilter.Install(_autoCompleteForm); } // set auto complete options _currentInput = _hostInterface.GetCurrentInput(); _currentInputNode = _currentInput.GetNodeAtPosition(_hostInterface.InputPosition); List <string> autoCompleteOptions = _provider.GetOptions(_currentInput, _currentInputNode); if (autoCompleteOptions != null && autoCompleteOptions.Count == 1) { string value = autoCompleteOptions[0]; if (value.IndexOf(' ') > 0) { value = string.Format("\"{0}\"", value); } _hostInterface.ReplaceCurrentNode(value); } else if (autoCompleteOptions != null && autoCompleteOptions.Count > 1) // only show if options are available { _autoCompleteForm.SetAutoCompleteOptions(autoCompleteOptions); // get the location of the caret, plus the line height as the auto complete form open point _autoCompleteForm.Location = GetPopupLocation(_hostInterface.CaretLocation, _hostInterface.RTB.SelectionFont.Height); // open the auto complete form _autoCompleteForm.Show(); // adjust key input filter settings _hostInterface.InputFilters.SetFilterMode(FilterMode.AutoComplete); } }
/// <summary> /// Installs a new auto complete message filter into the message loop for the given auto complete form /// </summary> /// <param name="autoCompleteForm">The auto complete form for which to install the message filter</param> public static void Install(frmAutoComplete autoCompleteForm) { Application.AddMessageFilter(new AutoCompleteMessageFilter(autoCompleteForm)); }