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:
- Subscribe to
MouseMove
on the first RichTextBox. - In the
MouseMove
event, checkMouse.Captured
to see if it is the RichTextBox. - 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 ofHitTestResult.VisualHit
to see if the mouse is over a RichTextBox other than the current one. - If the mouse is over a new RichTextBox, cancel the mouse capture with
Mouse.Capture(null)
, then fire aMouseLeftButtonDown
event on the new RichTextBox to cause it to capture the mouse and begin selection.
精彩评论