4

I'm developing a notepad clone. I would like to implement a block select as in textpad (vertical selection). How would I do that?

Textpad Block Select

EDIT: I don't know what kind of detail should be added to this question. However this is my code. I need to add block select functionality to this textbox.

<TextBox Name="txtContentBox"
         Text="{Binding Content, UpdateSourceTrigger=PropertyChanged}"
         VerticalAlignment="Stretch"
         Background="White"
         Foreground="#111111"
         BorderThickness="0"
         FontSize="{Binding FontSize}"
         FontFamily="{Binding CurrentFont}"
         FontStyle="{Binding IsItalic, Converter={StaticResource BoolToFontStyle}, ConverterParameter=Italic}"
         FontWeight="{Binding IsBold, Converter={StaticResource BoolToFontWeight}, ConverterParameter=Bold}"
         TextWrapping="{Binding IsWrap, Converter={StaticResource BoolToWrap}}"                                                          
         SelectionBrush="#6674AAE2"                             
         AcceptsReturn="True"
         AcceptsTab="True"
         VerticalScrollBarVisibility="Auto"
         HorizontalScrollBarVisibility="Auto"                             
         AllowDrop="True"
         SnapsToDevicePixels="False"
         MouseMove="txtContentBox_MouseMove"
         PreviewMouseDown="txtContentBox_PreviewMouseDown"
         PreviewMouseUp="txtContentBox_PreviewMouseUp">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="TextChanged">
            <cmd:EventToCommand Command="{Binding HandleChangesCommand}" />
        </i:EventTrigger>
        <i:EventTrigger EventName="PreviewMouseWheel">
            <cmd:EventToCommand Command="{Binding IncDecFontSizeCommand}"
                                PassEventArgsToCommand="True" />
        </i:EventTrigger>
        <i:EventTrigger EventName="Drop">
            <cmd:EventToCommand Command="{Binding OpenCommand}"
                                PassEventArgsToCommand="True" />
        </i:EventTrigger>
        <i:EventTrigger EventName="PreviewDragEnter">
            <cmd:EventToCommand Command="{Binding PreviewDraggedFileCommand}"
                                PassEventArgsToCommand="True" />
        </i:EventTrigger>
        <i:EventTrigger EventName="PreviewDragOver">
            <cmd:EventToCommand Command="{Binding PreviewDraggedFileCommand}"
                                PassEventArgsToCommand="True" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</TextBox>
akjoshi
  • 15,374
  • 13
  • 103
  • 121
Amsakanna
  • 12,254
  • 8
  • 46
  • 58
  • Those who vote to close, care to comment what other details you want? – Amsakanna May 12 '12 at 16:19
  • I haven't voted to close, but I do have a suggestion: you may want to add more details. Do you want just a generic theoretic description of how to do it? Or do you want to include more details of your text editor so that people can suggest how to do it with that specific control? – slugster May 13 '12 at 00:38
  • Block select is a very unusual requirement, so it's not baked in. You'd have to implement your own. Most people would probably recommend subclassing the textbox, which is also what I'd recommend. You would not be able to use any of the built-in selection logic as it is all based on the concept of start/end char index (which is not what you want). Basically, this question is extremely broad. Do you want to try narrowing the question a bit? – JDB Jun 04 '12 at 18:37
  • 1
    http://wiki.sharpdevelop.net/Default.aspx?Page=AvalonEdit&AspxAutoDetectCookieSupport=1 – Angshuman Agarwal Jun 09 '12 at 19:29

1 Answers1

3

You can use AvalonEdit. It's a native WPF editor that has this feature and many more.

Eli Arbel
  • 22,391
  • 3
  • 45
  • 71