I need to make a sort of text processor. It must have these features:
All the WordPad features + paragraph styles like MS Word + text
columns + Zoom.
Insertion of tables, images, and controls like buttons, checkboxes.
Text search and replacement, spell check.
Syntax coloring, like code or quote parts on the StackOverflow site.
Ability to move text paragraph on custom places via mouse (like OneNote)
Ability to add some simple diagram (hierarchic)
I found on the web that the best way to implement the above requirements is to use FlowDocument. I also found that WPF RichTextControl would have many required functionalities, but on StackOverflow it is written that it has bad performance.
So, does it exist a FlowDocument text processor control?
If not, from which control could I start in order to implement the above requirements?
Related
I am using RichTextBox in one of my WPF Application, users types Text\script in this rich text box, based on the tokens entered by user i apply color, font property to the entered text in the code behind(Syntax highlighting).
I need to perform Undo\Redo Operations, but what i found is the default undo operation works well if i am not changing the color\font properties, but if i change them in my code , it doesnt work.
I read many postings here which are mainly discussing about richtext box undo operations in C#, most of them suggested to use logic using stack and storing text and poping the text for undo\redo. But the problem i have in WPF is i need to know the TextPointers for inserting the text and also i need to know the operations like delete, add and copy paste text operations for my undo\redo operations.
Is there a way where i can perform these operations although property changes are done to text.
I'm currently spiking with the WPF RichTextBox before I decide whether or not it can be used in a project of mine.
What I need is to have elements of text representing various objects (other texts or objects), a bit like a WIKI but not quite. Clicking on such a text will make stuff happen, like navigating to other texts or providing additional options.
Anyway, as these little text bits represent other objects I would like to protect them but I have succeeded with this only in part: The user cannot position a caret inside such a text element and edit/delete it but it is still possible to make a selection and delete/replace it, including my custom elements.
Have anyone travelled down this road with the RichTextBox? My latest experiment was to simply record all custom text elements when being part of a selection and then restoring them after the (destructive) edit. That fell apart because I can't find a way to re-insert my custom inline elements (derived from the Run class). The only way I've found to programmatically insert a Run (based) element at a specified position (TextPosition) is via its constructor.
Well, any hints would be greatly appreciated.
You are really looking for a FlowDocument, not a RichTextBox.
I have a RichTextBox and need to serialize its content to my database purely for storage purposes. It would appear that I have a choice between serializing as XAML or as RTF, and am wondering if there are any advantages to serializing to XAML over RTF, which I would consider as more "standard".
In particular, am I losing any capability by serializing to RTF instead of XAML? I understand XAML supports custom classes inside the FlowDocument, but I'm not currently using any custom classes (though the potential for extensibility might be enough reason to use XAML).
Update: I ended up going with RTF because of its support for text-encoded embedded images. XAML doesn't seem to include image data in its encoding, and XamlPackage encodes to binary, so RTF just works better for me. So far I haven't noticed any lack in capability.
If all your users are doing is typing in the RichTextBox and doing character formatting, RTF is as good as XAML. However there are many FlowDocument capabilities you may expose in your UI that are not convertible to RTF.
Here are some examples of FlowDocument (and RichTextBox) features that are not expressable in RTF or are implemented differently:
A Block can have an arbitrary BorderBrush, including gradient brushes with stops, VisualBrush
A Section has the HasTrailingParagraphBreakOnPaste property
Floater / ClearFloaters is implemented differently
Hyphenation can be enabled/disabled per block, not just per paragraph
WPF Styles and ResourceDictionaries can be included in the Resources property
Arbitrary WPF UI such as bound CheckBoxes, etc, can be embedded inside the RichTextBox and can be cut-and-pasted from other windows.
For example, suppose you want to allow users to drag or cut/paste in a "current date/time" field into your RichTextBox that would always show the current date and time. This could be done by adding a second read-only RichTextBox that has the InlineUIContainer and the already-bound control. This even works when cutting and pasting from other applications and does not require custom controls.
Another consideration is that the code to convert between FlowDocument and RTF is relatively complex so it may have lower performance than going with XAML. Of course loose XAML doesn't include images and such - for that you need to use XamlPackage. I store my XamlPackage in the database as a byte[], but you can also choose to Base64 encode it for storage as a string.
The bottom line is that it really depends on whether you want the user to be able to use features not available in RTF. Even if your application doesn't include tools to generate FlowDocuments that use these features, it is possible to cut-and-paste them from other applications.
Be aware that in Wpf RichTextBox's method called TextRange.Save has a bug whereby it loses any end of line terminator. Microsoft will not fix.
https://connect.microsoft.com/WPF/feedback/ViewFeedback.aspx?FeedbackID=478640&wa=wsignin1.0#tabs
In order to make a convenient UI for an .Net 2.0 Winforms application I am working on, I have need for a control that I'm pretty sure goes beyond the "out of the box" behavior of any standard control. A mock-up of what I'm trying to achieve follows:
Mock up http://www.claware.com/images/temp/mockup.png
Essentially, this part of the application attempts to parse words into syllables from tribal languages (no dictionary to refer to; any and all unicode characters are possible.) By the time the user gets this far, he has already defined the vowels / consonants in his language and some other configuration. There is then an iterative process of (1) the application guesses which syllables exist in the language based on some rules, (2) the user refines the guesses, selecting the correct parsings or manually parsing a word, (3) the application "learns" from the user's feedback and makes smarter guesses, (4) repeat until the data is "good enough" to move on.
The control needs to present each word (the grey headers), then all the syllable break guesses (the white areas with dots separating the parts of words.) There is also a way to manually enter a parsing, which will display a text area and save button (at the bottom of the mockup.) When the user hovers over a guess, the background changes and "accept / reject" buttons appear. Clicking on the accept, or entering a manual parsing, removes the entire word from the list. Clicking the reject button removes just that item.
I'm by no means 100% sold on the formatting I have above, but I think you can get a general idea of the types of formatting and functional control I need. The control will also scroll vertically--there may be thousands of words initially.
My question for you experienced WinForms developers is: where to start? I would really, really like to stay within the .Net core framework and extend an existing control as opposed to a third-party control. (At the risk of starting a religious war: yes, I suffer from NIH-syndrome, but it's a conscious decision based on a lot of quick-fix solutions but long-term problems with 3rd party controls.) Where can I get the most "bang for my bucK" and the least reinventing the wheel? ListView? ListBox? ScrollableControl? Do I need to go all the way back to Control and paint everything manually? I appreciate any help that could be provided!
[Edit] Thanks everyone for the ideas. It seems like the most elegant solution for my purposes is to create a custom control consisting of a FlowLayoutPanel and a VScrollBar. The FlowLayoutPanel can contain instances of the custom controls used for each word. But the FlowLayoutPanel is virtual, i.e. it only contains those instances which are visible (and some "just out of scroll"). The VScrollBar events determine what needs to be loaded. A bit of code to write, but isn't too bad and seems to work well.
I would look at the TableLayoutPanel and FlowLayoutPanel controls. These will let you organize a series of controls with moderate ease in a vertical fashion. I would then create a UserControl that consists of a label and 2 buttons. The UserControl will expose properties like Text and events that are exposed for the button clicks.. For each entry in the list, you will create an instance of the UserControl, assign the text value, and handle the click events. The instance will be placed in the Table/Flow panel in the correct order. Both of those layout panels do allow for inserting items between other items so you can add/remove items from the list dynamically.
Edit:
Given the length of what you are trying to render, I would consider using the DataGridView and do some custom rendering to make it perform how you want it to work. Using the rendering events of the DGV you can merge columns, change background colors (like highlighting the dark gray lines), turn on/off the buttons, and handle changing the grid into edit mode for your rows to allow modification or inserting of new values. This method would easily handle large datasets and you could bind directly to them very easily.
Well, this certainly looks like a candidate for a custom component that you should be creating yourself. You can create this using standard .Net drawing commands along with a text-box, and a regular button control.
Now you want to find out where to start.
Create a Windows Forms Control Library project.
Drop in the textbox and the button control.
The panel drawing code should preferably be done by code. This can be done using the regular GDI+ commands.
Edit:
Here's another idea, and one that I've practically used in my own project with great success.
You could use a web-browser control in the app, and show your data as html. You could update the source of the web-browser control based on the input in the textbox, and clicking on the links in the web browser control will give you the event that you can trap to do some action. Your CSS will work.
I used this technique to build the 'desktop' in an app I made called 'Correct Accounting Software'. People loved the desktop so much that it is one of the best loved features of the app.
Here's how I would do it:
Create a custom control. In this custom control, have a ListBox atop a LinkButton, and when the LinkButton is clicked you can make it give way to a TextBox. The ListBoxes will have the top row unselectable... you can probably get the rest from there. When you get your list of words, fill a Scrollable of some kind with one control for each word:
(foreach String word in words){
myScrollable.add(new MyComponent(word));
}
From there, I'm not sure what you want to do with the boxes or the data, but that's my initial idea on the UI setup.
Use the WebBrowser control and generate the HTML markup into it using DocumentStream or DocumentText.
What is a good TreeView replacement with added features over the standard one that comes with vs.net 2008? please include both a free and commercial options.
TreeViewAdv has always been my favorite.
You could to take a look into RadTreeView for WinForms.
I know this is an old question, but here is a free and comprehensive list/tree view control I found on code project by Phillip Piper called ObjectListView.
It has all the standard features and more. It is well thought out and professionally made. I my opinion it easily stands up to the popular commercial solutions available. I would recommend it to any developer looking for a free feature-rich list/tree view control for their winforms application.
http://www.codeproject.com/Articles/16009/A-Much-Easier-to-Use-ListView
Here's a list of features from the documentation. http://objectlistview.sourceforge.net/cs/index.html
It easily transforms a collection of model objects in a fully functional ListView, including automatically sorting and grouping.
It can easily edit the values shown in the ListView.
It supports tri-state check-boxes (on, off, indeterminate), even in virtual mode, and on subitems.
It supports heavily customisable tool tips for both cells and column headers.
It can trivially produce nice reports from the ListView.
It supports all ListView views (report, tile, large and small icons).
It supports owner drawing, including rendering animated GIFs.
Its columns can be fixed-width or limited to a minimum/maximum.
It shows a highly customisable "list is empty" message when the list is empty (obviously).
Its row height can be explicitly set.
It supports user selection of visible columns by right clicking on the header.
It supports columns that automatically resize to fill any unoccupied width.
It supports hot tracking, with text font/color changes and with decorations.
It supports image and text overlays, as well as arbitrary overlays (the personal information box) and decorations (the love hearts).
It has extensive support for drag and drop.
It supports hyperlinks in cells.
It supports column headers being styled (normal, hot and pressed states), plus having images and even vertical text.
It supports many group formatting options, including collapsible groups. Groups can be shown on virtual lists!
It has a version (TreeListView) which combines a tree structure with the columns of a ListView.
It has a version (VirtualObjectListView) that supports millions of rows.
It has a version (FastObjectListView) that can build a list of 100,000 objects in less than 0.1 seconds.
It has a version (DataListView) that supports data binding, and another (FastDataListView) that supports data binding on large (100,000+) data sets.
It makes implementing your own virtual list simple through the IVirtualListDataSource interface.
It supports filtering, including showing and highlighting rows that match a given string (including regex and prefix match).
It supports animations on a cell, row or the whole list. [v2.4]
It supports Excel-style filtering. [v2.5]
Another name for such a component is TreeListView. If you need a WinForms TreeListView control that can be populate from a data table, look at iGrid.NET in TreeListView mode. You can do what you need with just one method call using this control.