FindText Method |
[Top] [Chapter] [Previous] [Next] |
Applies to Declaration void FindText( string Text, bool FromStart, bool CaseSensitive, bool MoveCursor, bool WholeWords, ref bool Found); Description
Locates a text and either moves the cursor before its location or selects the text with the cursor being after the found text.
Use Memo.SetIProp(11,-1) to make FindText search backwards.
Example 1 - implement a standard find dialog:
The dialog uses this relevant GUI elements:
private System.Windows.Forms.TextBox FindWhat; private System.Windows.Forms.CheckBox chkWholeWord; private System.Windows.Forms.CheckBox chkCaseSensitive; private System.Windows.Forms.RadioButton chkDown; private System.Windows.Forms.RadioButton chkUp; private System.Windows.Forms.Button btnFindButton; private System.Windows.Forms.Button btnCancelButton; private System.Windows.Forms.CheckBox chkFromStart;
This is the constructor:
// Must be assigned before the dialog is displayed! IWPMemo Memo;
public FindDialog(IWPMemo aMemo) { Memo = aMemo; InitializeComponent(); }
This code is executed when the "Find Next" button is pressed:
private void FindButton_Click(object sender, EventArgs e) { bool found = false;
// Change Find Direction if (chkUp.Checked) Memo.SetIProp(11, -1); // Up=backwards else Memo.SetIProp(11, 1); // Down
Memo.TextCursor.FindText(FindWhat.Text, chkFromStart.Checked, chkCaseSensitive.Checked, false, //if Movecursor=false then select the found text chkWholeWord.Checked, ref found);
if (found == false) MessageBox.Show("Text was not found!"); else chkFromStart.Checked = false;
}
To use the dialog You can call:
(new FindDialog(wpdllInt1.Memo)).ShowDialog();
Example 2 - modify the font of all occurrences of "some text".
IWPMemo Memo = wpdllInt1.Memo; IWPTextCursor TextCursor = Memo.TextCursor; IWPAttrInterface Attr = Memo.CurrSelAttr; bool ok = true;
int cp = TextCursor.MarkerDrop(0); TextCursor.GotoStart(); while(ok) { TextCursor.FindText("some text", false, false, false, false, ref ok); if(ok) { Attr.Clear(); Attr.SetFontface("Arial"); } } TextCursor.MarkerGoto(true, cp);
|