How can I wrap text from one text control to another? - c#

I'm attempting to create a program in C# that would allow dynamic wrapping across rich text box controls. For example, I begin typing in one available control, as soon as a horizontal scrollbar would appear and the rich text box wraps to the next line, it would instead create a new rich text box control underneath and place my cursor there. This method would also need to support moving text back and forth between controls in the case of deleting/changing existing text.
Why you ask? My church requires a program that will allow easily pasting text and it automatically going across as many slides as needed which supports different fonts, sizes, weights, colors, and undo and redo. All this would need to be done on the fly so the user does not need to use some sort of preview mode to go back and forth to accomplish what they're trying to do.

I assume this is for something like order of service, or words to hymns? The solution for that is to use the scrollbar or the PgDn button. In a Web Browser.
I agree with Chris Ballard. Really, this doesn't look like the right way to solve your problem.

Related

Custom Text Box Component / Element (Not a Control)

I am in need of a class that mimics a TextBox control but is not a Control, but instead a custom drawn component or element.
Creating one feels like re-inventing the wheel since I see them everywhere. For example, in any modern web browser the text boxes are not controls. Most Winforms controls, especially ToolStrip controls such as ToolStripTextBox, have elements which behave like text boxes (but are not Controls).
I assume that Microsoft doesn't reinvent the wheel for each control they make it. But most likely their code is proprietary and not public.
Does any one know of an open source solution for this? I am experienced with GDI+ drawing but a text field is not a trivial task when you consider caret positioning, selection, and inserting text.
Any pointers on how to go about writing the code myself would be appreciated, such as how to calculate the character at a given point. Should I create a lookup table for the measured width of each possible character? Or loop through MeasureString to take into account formatting space?
You may find the code you need inside this article/project. http://www.codeproject.com/Articles/161871/Fast-Colored-TextBox-for-syntax-highlighting
Why must it not be a Control? If you're using Windows Forms, it is far more likely that you really want a control.
Common cases where this type of question might come up are Grid editing. Instead of a non-control TextBox, what normally happens is that the grid displays simple text in the grid until the user focuses on that grid. At that point a temporary, real TextBox is inserted for editing. Leaving that cell throws the TextBox away and the possibly-changed text is now displayed by the Grid.
I assume your situation is similar. If not, please explain your goals.

c#/.NET/Winforms RichTextBox : Highlight active line

I'm making a very simple text editor and I'd like to color the background of the whole selected line (left to right). And I'd like it to follow the cursor so if I go down two lines the background changes.
I'm looked a lot on here and google and found nothing interesting, it always colors the text instead of the background and it does not color the entire line, etc.
Any suggestions are welcome!
Thanks!
I am not sure you can easily color the full line where the caret is in the standard RichTextBox control, I think I mostly heard only the background of already entered text could be colored.
If you are not forced to stay with the standard RichText you can have a look at this:
ScintillaNET
this editor has an incredible amount of features, the only thing is that I am not sure if it supports many different fonts otr picture embedding, tables and so on.
if ScintillaNET is nout enough either I would then try with DevExpress components for Windows Forms, extremely feature rich and powerful, in theri demo they have basically made a text editor with tables, mailmerge and so many other things it looks almost like MS Word.

Limiting a multi-line text box input so that everything will be printed

I'm sure this is a common problem, I don't know if there is a common solution. My problem is when the user is viewing said multi-line text box in the GUI they can just scroll down, not a problem. When I come to print however, certain text occasionally ends up going off the bottom of the given area for that text box.
We'll keep it simple and say it is not a rich text box so the user can't choose a larger font which may therefore go off the page. hmmph cross that bride if I need to =)
So I considered;
Using a character limit but then if you just return carriage a number of times, this would end up going off the bottom.
Or a 'row' limit which i'm not entirely sure how to implement but didn't seem right either
Finally I am coming to the conclusion that when you print said multi-line text box you must just expand the area on the printed document to fit whatever text has been entered. If this is the most elegant solution can anybody point me in the right direction for implementing such a feature?
Think of a notes field where the user could type as much as they wanted and the intention is to make sure all that is typed is printed.
Are you calling yourTextBox.DrawToBitMap? All that does is create a bitmap of what appears on the screen, it does not perform printer output, line layout, line breaks, printer fonts, margins, orientation, pagination, or anything else to do with printing.
If you want to send text to a printer, handling all the features mentioned above, you will have to use the System.Drawing.Printing.PrintDocument class and deal with all the things printers require that textBoxes do for you.
How and why are you printing a WinForm? I know this doesn't answer your question but printing a WinForm as a document is going to have these types of issues and I can guarantee that as you release your application to more users, more quirks will arise that will need to be fixed.
If you absolutely must print the Form and you want to limit the content in your TextBox about the best solution that I can offer is to force the font to be a fixed width font of a fixed size and the user can't modify it. Count how many characters can fit in the TextBox and set that value as a MexLength on the control.
Obviously, the user can hit the return/enter key which will use one character but will consume one entire line. To fix this, changed the TextBox's TextChange event to handle the newline character-- you can either strip it from the text or update the TextBox's MaxLength property to a smaller, appropriate value.
With possibly a few minor tweaks, obvious tweaks my recommendations should safely get you what you want. Still, I highly recommend looking for another printing mechanism for your form.
Use at your own risk.

Mimicing Tcl/Tk's Font "OnMouseEnter" behavior in a C# application

I was looking at a program my friend sent me that was written in Tcl/Tk. It has a rich-formatting multi-line text box with different colors and fonts, and for certain blocks of text the application window reacts to users hovering over different text elements. He says this is implemented by specifying a "OnMouseEnter" callback event when creating a new font. This seems like a cool and elegant approach, and I wanted to do something similar in a C# app I wrote. At the moment the three ways I can think to do this are: (a) work out the mapping from X-Y mouse coords to text (maybe there is an easy function for this?) (b) make each distinct text block a child control with its own callback functions (which is very ugly and would require me to do my own text wrapping) or (c) make it a webpage control and have javascript "call" C# via WebBrowser.Navigating. Any suggestions as to the best way to implement this kind of functionality would be welcome.
Most textbox control have X-Y coord to text block translation function calls. You can hook the entire mouse move event for the textbox and see what's beneath the mouse.
This might be ugly code but at least it would work.

RichTextBox control, making non-URLs hyperlinks?

In a richtextbox I see there's DetectURLs and an event to go along with that...
Is there a way to set up a word or series of words to act as a hyperlink even though they are not a hyperlink? My specific use is that I'm writing a ticker program that will scroll information across the bottom of the screen, I would like for some information to be clickable without putting the long, messy URL of the target. Anyway I can do this?
Links with arbitrary text in a RichTextBox
http://www.codeproject.com/Articles/9196/Links-with-arbitrary-text-in-a-RichTextBox

Categories

Resources