3
Answers

Mouse event in implementing dictionary

Ask a question
Hi 
I am building a dictionary. this is the feature of my dictionary which I am trying to add to my dictionary : User highlight the word in any application or Double Click on the word after that the word will copy to the dictionary and the meaning should retrieve automatically. This is the code which I used for this but I', having a problem here and that is when the user Highlight the word or double click the word, he/she needs to Click anywhere of the screen again to retrieve the needed word in the dictionary. I assign the CTRL+C to the Mouse down function to copy the selected word to Clipboard and some more code to retrieve it in the Textbox in the dictionary. I don't know how to solve this problem. I want to paste the needed word ONCE the user HIGHLIGHT it or Double Click on it. but now it needs one more extra click to copy and paste the word. This is my code : ]

void mouseHook_MouseDown(object sender, MouseEventArgs e)
        {
            SendKeys.Send("^c");

        }
        void mouseHook_MouseUp(object sender, MouseEventArgs e)
        {
            
          
           // Int32 miliseconds_to_sleep = 9000;
           // Thread.Sleep(miliseconds_to_sleep);
            this.textInfo.Text = "MouseUp.";
            
          
            IDataObject iData = Clipboard.GetDataObject();

            // Determines whether the data is in a format you can use.
            if (iData.GetDataPresent(DataFormats.Text))
            {
                // Yes it is, so display it in a text box.
                textBox1.Text = (String)iData.GetData(DataFormats.Text);
            }
            else
            {
                // No it is not.
                textBox1.Text = "Could not retrieve data off the clipboard.";
            }
          
        }


I think the problem is when the user highlight the word , it need the second MOUSE DOWN event to copy the word and Second Mouse Up event to retrieve the word from clipboard. But I want everything happend in the first time that the user highlight or double-click on the word.
hint: I tried put the code in the Mouse Up event but it doesn't work at all. 

Answers (3)