I feel like I'm missing an obvious point here, but let's say I'm working on a text editor, and I'd like to store a file's (partial?) contents as a text buffer. My text buffer is some specialized data structure for holding lots of text, not just a simple string or StringBuilder. I'd also like to expose the text to the user, probably through a standard text box or rich text box.
What is the best means of doing this?
Would I copy a segment out of the buffer into the textbox, then adjust everything manually and copy changes back? Would I copy the entire buffer as a string into the textbox? If I was only loading part of a file into the buffer (to handle very large files) would I have to set up a second translation layer from buffer to file? Do I need an entirely different control from the built in textboxes to accomplish this?
EDIT: I'd also accept suggestions for 3rd-party text controls that would work well. My main block here is not wanting to build/learn/import the entirety of (for example) GTK or QT just to get a decent text editor control.
See the ebook referenced from this question, the sharpdevelop guys go into some detail on how to construct a text editor.
I use a RichTextBox in logview4net as a window on whatever data I'm looking at.
It is only forward scrolling and I can't really say I like it.
I think you're better off looking for some other editor control.
Related
I'm learning how to code C# from scratch. Right now, I'm learning how to build a scene on the command line and update it as necessary.
Part of what i want to do is to "scroll text as it is generated".
The scene is a square command line (Size 100 by 40) and outlined by a box of "#" characters. This is the canvas on which everything is presented.
As the user interacts via simple inputs, the program will provide textual feedback, like a text-based game.
However, unlike a normal text-based game, I cannot allow for the natural flow of the command line to move the canvas. In other words, if I allow for the command line to act naturally, then the canvas would slowly travel upwards until it's no longer visible.
I need a way to read whatever is already being presented on the screen and storing it on memory. Then, I can delete a portion of the screen an paste the previously copied information shifted upwards, making space for new information.
Here is a mockup of what I want to do:
Image 1: desirable outcome
My question is: Is there a way to "read" only a specific portion of the command space and store into memory?
I know you can store whatever is being printed at the moment of printing, or I could keep track of a certain number of previously displayed information and print it again, but I would like to "copy, then paste shifted" a portion of the screen.
PS: This is what I'm trying to avoid
Image 2: Undesirable outcome
Since the top line needs to be moved too, really the only way to do this is to clear the screen and redraw everything. Instead of printing directly to the screen, save the new line to a list, clear the screen, then print that list to the screen, together with the border.
While I haven't found a way to store a portion of the command line to a variable for later use, I've succesfully "scrolled" the text, and found a workaround to "store" it.
Simply put, Console.MoveBufferArea() allows one to select a portion of the command line buffer and move it somewhere else on the buffer.
This way I can:
-Clear whatever space i need at the top by moving the cursor to, say, (1,1) and writing a box of spaces via a string.
-Console.MoveBofferArea() the portion of the buffer a few rows upwards
-Write the new text at the bottom
As a byproduct, i can also "store" a portion of the screen for late use by:
-Setting the buffer to a wider area with Console.SetBufferSize()
-Use Console.MoveBufferArea() to the buffer portion that is outside of normal view
-Do whatever i need to do on the screen
-Use Console.MoveBufferArea() to retrieve the "stored" portion back to where i need it
-Reduce the buffer area (I could also just leave it be)
I have some text printed in my C# console (Lots of it) and I am wondering what would be the simplest way to change the text color all at once without clearing the console and reprinting it in the new color, sort of having the same effect as System(color ##) command in C++...Thanks in advance.
You can change the console output color using Console.BackgroundColor and Console.ForegroundColor properties. After you are done writing in the new color, use Console.ResetColor() to go back to defaults.
Changing the colors after the fact is a problem, because C# has no direct way to read text at a given position.You can rewrite it however, if you know what exactly is there, in a different color (first jumping to the location using Console.SetCursorPosition method and then writing over the original text).
If you want to be as efficient as possible, you will need a higher caliber in form of some P/Invoke wizadry. This is quite well described in the accepted answer to this similar question. The solution there takes advantage of writing the entire Console buffer at once, which is very fast.
I'm looking for basically fastest way to display non-editable FlowDocument with continuous, variously decorated text.
I know RichTextBox and usually use FlowDowcumentScrollViewer that can display FlowDocument content.
I know TextBlock can (kind of) be fed Inlines in code, but doens't support Paragraphs etc.
But did anybody measure which of the former two are faster with different occasions (scrolling / non scrolling, long / shorter document etc.) ?
Or is there some other, more effective solution ?
Some people claim that FlowDowcumentScrollViewer is actually slower because it supports more (advanced) formatting scenarios. Not sure if thats true.
On the other hand RichTextBox has all the editing functionality etc. that drags its speed down.
As Im currently writing a RichText heavy application, I would be glad for any tips on this
I need to create a windows store application with e reader functionality. I have to provide a fluid reading experience. Currently, my knowledge of displaying text consists of dropping textblock or textbox on the UI. I do not know how to display large amount of text to create the E Reader experience i am looking for. Which control or combination of controls should i use?
Your text rendering options are
XAML controls
TextBlock
RichTextBlock
WebView + WebViewBrush
DirectWrite - what all the above ultimately use. You can use it with C# through SharpDX.
The controls might be a bit cumbersome to use at times if you need to do measurements etc. and might not give you as much power or performance as DirectWrite does, but will give you support for text selection, copying to clipboard etc. (make sure IsTextSelectionEnabled is set to true).
For measuring text dimensions for paged display in a TextBlock - create a TextBlock in code behind and call Measure() and Arrange(), then get ActualWidth/ActualHeight to get the measurement.
Read Charles Petzold's Principles of Pagination article.
Consider Rapid Serial Visual Presentation (RSVP) speed-reading method used in the ReadQuick app.
I'm trying to replace a section of a PDF with different text. From research on all major PDF libraries for .NET, it seems this is complicated and not a trivial task. I think it may be easier to convert the PDF to an image, replace the text (always in the same place), then convert it back to a PDF (or leave it as an image if converting back isn't possible). Is it possible to extract an image from a PDF page with .NET?
If your text is in a known location, you can simply cover it with a rectangle filled with the background color, and then draw your text over top.
Note that the text will still be there, it simply won't be visible. Someone selecting text will still pick up the old stuff. If that's acceptable, it's quite trivial.
If the PDF was created from image, you can import it into Photoshop to edit it as an graphic. Or you can use screenshot program like "Snagit" to capture pdf page as image and use snagit's editor to erase old text and replace new one.
But this method may bring you problem is that the new added text may not the same font as text around it. Personally, I use pdf editor to replace text in pdf since the added text will be automatically fit with the original font and size.