none
Select the word i'm typing RRS feed

All replies

  • Hi Kazi Fazlee Rabbi,

    its looks like you want to find the word "i'm typing" in word document.

    you can find it by selection object or by range object.

    Using selection object:

     private void SelectionFind() 
            { 
                object findText = "find me";
    
                Application.Selection.Find.ClearFormatting();
    
                if (Application.Selection.Find.Execute(ref findText,
                    ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                    ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, 
                    ref missing, ref missing)) 
                { 
                    MessageBox.Show("Text found.");
                } 
                else
                { 
                    MessageBox.Show("The text could not be located.");
                } 
            }
    
     

    using Range object:

     private void RangeFind() 
            { 
                object findText = "find me";
    
                Word.Range rng = this.Paragraphs[2].Range; 
    
                rng.Find.ClearFormatting();
    
                if (rng.Find.Execute(ref findText,
                    ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                    ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, 
                    ref missing, ref missing)) 
                { 
                    MessageBox.Show("Text found.");
                } 
                else 
                { 
                    MessageBox.Show("Text not found.");
                } 
    
                rng.Select(); 
            }
    

    Reference:

    How to: Programmatically Search for and Replace Text in Documents

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 16, 2016 12:51 AM
    Moderator
  • thank you for your reply.but i dont want to search for a specific word.instead i want to catch the string or word the user is typing. 
    Saturday, December 17, 2016 4:56 AM
  • i want to catch the word or string the user is typing .how can i do that?thank you
    Saturday, December 17, 2016 9:28 PM
  • Hi Kazi Fazlee Rabbi,

    I find that you created a duplicate thread with the same issue.

    so to avoid the duplication of threads I merge these both cases.

    you can carry your conversation on this thread to get the solution for your issue.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 19, 2016 12:32 AM
    Moderator
  • Hi Kazi Fazlee Rabbi,

    first of all I want to inform you that when you post the question on the forum at that time try to describe your issue with as much as possible details. so that we can try to understand the issue correctly and try to provide suggestion accurately. with your one line of description all we understand that you want to find the text in word document.

    now it's clear that you want to fetch the characters type by the user by keyboard.

    so VSTO doesn't have any method that can catch the catch the characters typed by the user.

    you can try to use Keyboard hook for windows forms c#. with that help of that you can get the characters typed by the user. you can try to add References to the System, System.Drawing and System.Windows.Forms assemblies in your VSTO project.

    please Refer the example mentioned below.

    using System;
    using System.Drawing;
    using System.Windows.Forms;
    
    namespace KeyboardInputForm
    {
        class Form1 : Form
        {
            TextBox TextBox1 = new TextBox();
    
            [STAThread]
            public static void Main()
            {
                Application.EnableVisualStyles();
                Application.Run(new Form1());
            }
    
            public Form1()
            {
                this.AutoSize = true;
    
                FlowLayoutPanel panel = new FlowLayoutPanel();
                panel.AutoSize = true;
                panel.FlowDirection = FlowDirection.TopDown;
                panel.Controls.Add(TextBox1);
                this.Controls.Add(panel);
    
                this.KeyPreview = true;
                this.KeyPress +=
                    new KeyPressEventHandler(Form1_KeyPress);
                TextBox1.KeyPress +=
                    new KeyPressEventHandler(TextBox1_KeyPress);
            }
    
            // Detect all numeric characters at the form level and consume 1, 
            // 4, and 7. Note that Form.KeyPreview must be set to true for this
            // event handler to be called.
            void Form1_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (e.KeyChar >= 48 && e.KeyChar <= 57)
                {
                    MessageBox.Show("Form.KeyPress: '" +
                        e.KeyChar.ToString() + "' pressed.");
    
                    switch (e.KeyChar)
                    {
                        case (char)49:
                        case (char)52:
                        case (char)55:
                            MessageBox.Show("Form.KeyPress: '" +
                                e.KeyChar.ToString() + "' consumed.");
                            e.Handled = true;
                            break;
                    }
                }
            }
    
            // Detect all numeric characters at the TextBox level and consume  
            // 2, 5, and 8.
            void TextBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (e.KeyChar >= 48 && e.KeyChar <= 57)
                {
                    MessageBox.Show("Control.KeyPress: '" +
                        e.KeyChar.ToString() + "' pressed.");
    
                    switch (e.KeyChar)
                    {
                        case (char)50:
                        case (char)53:
                        case (char)56:
                            MessageBox.Show("Control.KeyPress: '" +
                                e.KeyChar.ToString() + "' consumed.");
                            e.Handled = true;
                            break;
                    }
                }
            }
        }
    }

    Reference:

    How to: Handle Keyboard Input at the Form Level

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, December 19, 2016 12:55 AM
    Moderator
  • thank you again for your reply.sorry for the short description.what i want to do is to catch the word or string the user is currently typing in microsoft word to check the word against a database .the user is writing on word not on form.i want to develop an auto suggest for other language.
    Friday, December 23, 2016 2:03 PM
  • Hi Kazi Fazlee Rabbi,

    you had mentioned that,"the user is writing on word not on form".

    I know that user is typing on a word document.

    what I mean that you have to implement above mentioned code in your VSTO Word project.

    then it will work with Word document.

    this is the only way to fulfill your requirement. because VSTO does not have any method or property to fetch the text typed by user.

    you had mentioned that ,"you want to develop an auto suggest for other language."

    in that case generally we use Textbox. because Textbox has Textbox_change event. so we can get the text typed by user.

    unfortunately word document doesn't have any event.

    you can refer the link mentioned below for Document Events.

    Document Events

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 26, 2016 6:15 AM
    Moderator