RichTextBox control, making non-URLs hyperlinks? - c#

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

Related

Recommendations for painting a custom text viewer

I want to develop a file viewing program for a specific read-only file format and for the most part it will just be scrollable text. The ultra-simple way is of course to use an existing text display controls, but I've come to the conclusion that I want a graphical sort of "custom colored highlighting", text coloring, and maybe other things painted in. So I was planning to handle the painting myself. I take it that attempting to line up my own graphics on top of a label or rich text box would be a bad idea, so I was planning to just paint everything except the scroll bar... unless these labels/rich text controls are a lot more extensible in some way that I don't know about?
Assuming I go the painting route, I'm not 100% sure of the specifics. Do I paint directly into a Panel? Or is there a better GUI control to paint into? Also, I think it will be better if I don't buffer the screen because I think repainting the contents on validation will be easy/efficient... but repainting from a buffer might be even faster... will it save me a lot of trouble if I just have a screen buffer... is this significantly inefficient? Is my plan of painting directly into a Panel, unbuffered, a good idea or is there a preferred method that I'm passing up?
Try to use WebBrowser control orRichTextBox (make formatted html or rtf from your text).

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.

How to accept text input in UserControl / ScrollableControl?

I've created a canvas like control that draws images, shapes and text. Right now text can be added to the drawing surface only programmatically. But I would like to implement a more WYSIWYG-like text input method. So the basic idea is to capture keystrokes inside my ScrollableControl implementation.
This seems to be a trivial task - just override OnKeyDown method, right? Not quite :( This basically means that I'd have to manually handle all possible key combinations with SHIFT or ALT (for non-english alphabets).
So the question is: is there an easy way to do it? Note that not only text input is required, but also backspace, enter, cursor movement and all that stuff. I feel I'm missing something and manual input handling through OnKeyDown is not exactly the best solution.
Depending on how you want the text input to work, you can probably do it by adding a borderless textbox to your control and focusing it when the user starts typing.

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.

How can I wrap text from one text control to another?

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.

Categories

Resources