Results 1 to 3 of 3

Thread: WPF RichTextbox - double click word selection

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2003
    Location
    Birmingham, AL
    Posts
    188

    WPF RichTextbox - double click word selection

    Is there a property or a way to stop words from being selected when i double click?

    If i double click on "microsoft" in www.microsoft.com (as a hyperlink in the rtb) microsoft becomes the selected text.

  2. #2
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: WPF RichTextbox - double click word selection

    override the doubleclick method and in the method body put some code to let the text selection equal none. You could also just handle the event rather than using override. so:

    VB Code:
    1. Private Sub ClearSelection (...) handles myRTB.ondoubleclick
    2.     'Stuff
    3. End Sub

    personally I would handle the event rather than overriding the original method as it is a cleaner way to code.

  3. #3
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: WPF RichTextbox - double click word selection

    Of course you can also use XAML to route the event through to your event handler and then you dont need the "handles" statement at the end of the event signature (apparently this is a more 'wpf' way of doing things but I cant actually tell you the advantages in this scenario), then if you had multiple RTBs that you wanted to apply this to then you could specify it in each one (although there is probably a way to do this with a style so you dont have to type it in each RTB declaration):

    Code:
    <RichTextBox MouseDoubleClick="RichTextBox_MouseDoubleClick" Height="100" Width="200"  />
    <RichTextBox MouseDoubleClick="RichTextBox_MouseDoubleClick" Height="100" Width="200" />
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width