FindText Method

[Top]  [Chapter]  [Previous]  [Next]

Applies to



void FindText(

  string Text,

  bool FromStart,

  bool CaseSensitive,

  bool MoveCursor,

  bool WholeWords,

  ref bool Found);



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.




The text to be searched and selects it or moves the cursor.


TRUE to start at the beginning of the text


TRUE to search case sensitive


TRUE to move the cursor to the found position.

Otherwise the text will be selected and the cursor will not be moved after the selection. This way a subsequent find operation will locate the next occurrence.


TRUE to find whole words only.


Will be set to TRUE if the text was found.


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;




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





                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.FindText("some text", false, false, false, false, ref ok);







            TextCursor.MarkerGoto(true, cp);


[idh_iwptextcursor_findtext.htm]    Copyright © 2007 by WPCubed GmbH