开发者

WPF richtextbox selection problem

i have two richtextboxes one below the other in my application.when the user start selection in one richtextbox and continue to the other richtextbox selection should automatically move to the second richtextbox.is there any way to do this type 开发者_如何学编程of selection.

thanks in advance, dhyanesh


You'd think you could use MouseEnter and MouseLeave, but when the mouse is captured (as it is during text selection), these events don't fire as expected.

The way to achieve your goal is:

  1. Subscribe to MouseMove on the first RichTextBox.
  2. In the MouseMove event, check Mouse.Captured to see if it is the RichTextBox.
  3. If the mouse is captured, do a hit test on the mouse's current postion using VisualTreeHelper.HitTest. Go up the visual tree from the value of HitTestResult.VisualHit to see if the mouse is over a RichTextBox other than the current one.
  4. If the mouse is over a new RichTextBox, cancel the mouse capture with Mouse.Capture(null), then fire a MouseLeftButtonDown event on the new RichTextBox to cause it to capture the mouse and begin selection.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜