FindText Method

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

Applies to

IWPTextCursor

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.

 

Parameters

Text

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

FromStart

TRUE to start at the beginning of the text

CaseSensitive

TRUE to search case sensitive

MoveCursor

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.

WholeWords

TRUE to find whole words only.

Found

Will be set to TRUE if the text was found.

 

Example 1 - implement a standard find dialog:

 

finddialog2

 

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

 


[idh_iwptextcursor_findtext.htm]    Copyright © 2007 by WPCubed GmbH