मेरा समाधान आप जो चाहते हैं उसे हासिल करने के लिए एक चाल का उपयोग करता है।
जब आप किसी टेक्स्ट क्षेत्र के अंदर डबल क्लिक करते हैं, तो यह अंतर्निहित शब्द का चयन करता है।
तो RichTextBox
(TextBox
माउस इवेंट्स पर फ्लैश करता है) का उपयोग करके आप अपने फॉर्म पर डबल क्लिक अनुकरण कर सकते हैं जब मध्य माउस बटन क्लिक किया जाता है (बाबुल शब्दकोश की तरह कुछ)। यदि आप चाहते हैं कि MouseDown
के बजाय आप MouseHover
का भी उपयोग कर सकते हैं। यह काम करता हैं।
public partial class Form3 : Form
{
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
public Form3()
{
InitializeComponent();
timer.Interval = 50;
timer.Tick += timer_Tick;
}
void timer_Tick(object sender, EventArgs e)
{
timer.Stop();
MessageBox.Show(richTextBox1.SelectedText);
// do more stuff here, e.g display your tooltip for the selected word or anything else
richTextBox1.SelectionLength = 0; // remove the highlighted color of selection
}
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
private const uint MOUSEEVENTF_LEFTDOWN = 0x02;
private const uint MOUSEEVENTF_LEFTUP = 0x04;
private const uint MOUSEEVENTF_RIGHTDOWN = 0x08;
private const uint MOUSEEVENTF_RIGHTUP = 0x10;
public void DoMouseDoubleClick()
{
//Call the imported function with the cursor's current position
uint X = (uint)Cursor.Position.X;
uint Y = (uint)Cursor.Position.Y;
mouse_event(MOUSEEVENTF_LEFTDOWN, X, Y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTDOWN, X, Y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
timer.Start(); // some delay is required so that mouse event reach to RichTextBox and the word get selected
}
private void richTextBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Middle)
{
DoMouseDoubleClick();
}
}
}
स्रोत
2012-10-25 15:20:38
धन्यवाद, यह शानदार ढंग से काम करता है! मुझे रेगेक्स भी पसंद आया जो सफेद जगह को बाहर निकालने के लिए भी इस्तेमाल किया जाता था! :) – Jammerz858
खुशी है कि आपको यह पसंद आया। ध्यान दें कि यह केवल सफेद स्थान को नहीं हटाता है। यह केवल रेगेक्स को एक शब्द मानता है, इसलिए विराम चिह्न और किसी अन्य शब्द को एक शब्द नहीं माना जाता है। –