示例#1
0
        /// <summary>
        /// Starts a find operation using the specified find data.
        /// </summary>
        /// <param name="owner">The dialog owner.</param>
        /// <param name="findData">The data to find.</param>
        /// <param name="findMode">Whether to find next, previous, or display a dialog.</param>
        /// <returns>True if the find text was found and selected.  False otherwise.</returns>
        public bool Find(IWin32Window owner, FindData findData, FindMode findMode)
        {
            this.Data = findData;

            // Use this.Data instead of findData in case the user passed in null.
            using (IFindDialog dlg = this.Data.CreateFindDialog())
            {
                bool result;
                switch (findMode)
                {
                case FindMode.ShowDialog:
                    result = this.Find(owner, dlg);
                    break;

                case FindMode.FindPrevious:
                    result = this.FindPrevious(owner, dlg);
                    break;

                default:
                    result = this.FindNext(owner, dlg);
                    break;
                }

                return(result);
            }
        }
示例#2
0
        /// <summary>
        /// Finds the specified text in the target.
        /// </summary>
        /// <param name="findData">The text to search for.</param>
        /// <param name="findMode">Whether to find next, previous, or display a dialog.</param>
        /// <returns>True if the find text was found and selected.  False otherwise.</returns>
        public bool Find(FindData findData, FindMode findMode)
        {
            TextBoxFinder finder = new(this);
            bool          result = finder.Find(this, findData, findMode);

            return(result);
        }
示例#3
0
        /// <summary>
        /// Used to display the Find dialog with the given data.
        /// </summary>
        /// <param name="owner">The dialog owner.</param>
        /// <param name="data">The find data.</param>
        /// <returns>True if OK was pressed.</returns>
        public bool Execute(IWin32Window owner, FindData data)
        {
            this.Text              = data.Caption;
            this.findText.Text     = data.Text;
            this.matchCase.Checked = data.MatchCase;
            this.searchUp.Checked  = data.SearchUp;

            bool result = false;

            if (this.ShowDialog(owner) == DialogResult.OK)
            {
                data.Text      = this.findText.Text;
                data.MatchCase = this.matchCase.Checked;
                data.SearchUp  = this.searchUp.Checked;
                result         = true;
            }

            return(result);
        }
示例#4
0
        /// <summary>
        /// Called to execute the dialog.  This allows you to do custom actions before
        /// and after the dialog is executed.
        /// </summary>
        /// <param name="findDialog">The dialog to display.</param>
        /// <param name="owner">The dialog owner.</param>
        /// <param name="findData">The find data.</param>
        /// <returns>True if OK was pressed.</returns>
        protected virtual bool OnDialogExecute(IFindDialog findDialog, IWin32Window owner, FindData findData)
        {
            bool result = findDialog.Execute(owner, findData);

            return(result);
        }
示例#5
0
        /// <summary>
        /// Handles displaying the find dialog.
        /// </summary>
        /// <param name="findDialog">The dialog to display.</param>
        /// <param name="owner">The dialog owner.</param>
        /// <param name="findData">The find data.</param>
        /// <returns>True if the user pressed OK.</returns>
        protected override bool OnDialogExecute(IFindDialog findDialog, IWin32Window owner, FindData findData)
        {
            // Initialize the find text from the selection.
            string?oldFindText = null;

            if (this.textBox.SelectionLength > 0)
            {
                // Only use the selection if it is one line or less.
                string selectedText = this.textBox.SelectedText;
                if (selectedText.IndexOf('\n') < 0)
                {
                    oldFindText   = findData.Text;
                    findData.Text = this.textBox.SelectedText;
                }
            }

            // Call the base method to display the dialog.
            bool result = base.OnDialogExecute(findDialog, owner, findData);

            // If they canceled, then we may need to restore the old find text.
            if (!result && oldFindText != null)
            {
                findData.Text = oldFindText;
            }

            return(result);
        }