Highlight/bold one char in label - c#

I'm programming IDE/interpreter/debugger for various esoteric languages. I would like to be able to bold one character at a time, in varying places (depending on code flow), for the debugger. I'm using WinForms for that. So in short, I would need to be able to bold one character of the text and send it to label. Thanks in advance.

You should have to paint/draw text using GDI API - handle paint event or override onPaint().

Related

Free Text Box width limit/wrapping

Hi I use the Free Text Box in my .net application.
I was wondering if there was a way to prevent someone typing one single huge line of text.
Can you set a wrap boundary on it?
I had a short read of the documentation, and I don't think you'll find a native way to do so.
I guess you could use the FreeTextBox.TextChanged event, and check every line in the FreeTextBox.Text property. Mind the fact that it is HTML, and you will probably have to parse it with another third party tool (doing it manually will only give you headaches).
If any of these lines has more characters than an arbitrary length you'll set, create a new line of text with the surplus character, and move the caret to this line.

C# keyboard and word prediction

I'm currently developing a C# desktop application which is a simple virtual keyboard with word prediction facility.
The prediction process will start after typing the first three letters of the word, then provide the suggestions. I need to track the caret while typing, and I tried to use richTextBox events such as SelectionChanged but it requires regular expression check and position tracking manually ( declaring variables ... ).
My questions: is there any suggestions that can help me in doing this task ? What about Listeners? are they helpful?
Note: I have no long experience with .NET framework and I didn't use Listeners before.
Also note that the input method is eye gaze ! which means non of key- events will work !
Thank you.
Will this be in WPF or WinForms? I would tackle this problem as follows. Maybe not the fastest way but worth to try until you have something else.
OnKeyDown event of your RTB check if the last char was a space. If not get whole word from last space and check against list of words and update the list on screen.
to check where the cursor is at the time in your word just do the same as above and try to get the current word and than the indexof specific key.

How to get width of a string in plain c#

I have an application where we replace place holding text with other text at run time.
While doing so I have to add character ellipses if the string goes beyond some predefined width.
So I do not have a DrawingContext available nor i have a Graphics.Measure available.
I used FormattedText but I was unable to extract the ellipted text.
I could never find the right way to use a formatted text like this.
Please help.
For WinForms, you can use the TextRenderer.MeasureText function,
and thanks to the comment from vcjones, using the method described at http://smellegantcode.wordpress.com/2008/07/03/glyphrun-and-so-forth/ for WPF.

Want to bold few characters of a word get bold in treenode in winforms using c#

i have "search TextBox" to search in treeview, i give result very well. But i want to get those parts get Bold which i typed in "search TextBox" of my winform.
Ex: i Typed Ram then it gives *Ram*esh .
The TreeNode class doesn't support that, its Text is always drawn with one font, the TreeView.Font. Making parts of the text bold is technically possible but very hard to get right. You need to enable custom drawing with the TreeView.DrawMode property and DrawItem event, there's a good example of it in the MSDN Library article.
That's the easy part, the hard problem is that the node is too small to fit the text after you draw parts of it in a bold font. TreeView is missing a "MeasureNodeText" event that would allow you to ask for enough space. The only workaround for that is to lie about the node text and make it artificially wider by prefixing characters. Which you then don't draw in the DrawItem event. Very hard to get consistently right, you'll want to consider a fixed pitch font instead.
I cannot recommend you pursue this unless the feature is really important to you. This otherwise explains why you never see this feature in other programs. Consider changing the color instead of the font weight too. Still hard to glue the pieces together btw.

how do I get the height of a rich text content after word wrap?

Question A.
Given
A string in rich text format that may have paragraph, tabs, space, line break, indentation, (or even image?)
A width for the word wrapping rich text control/editor
How do I know the height of the content after it have performed all the word wrapping?
Is there something like
int MeasureRichTextHeightAfterWordWrap(string aRichTextContent, int aWidth)?
Otherwise how does those rich text control know how much to autosize?
Do I have to actually place the content on a dummy rich text control, set it's width and get its height with GetPositionFromCharIndex(TextLength-1) afterwards?
Although this does work, it seems to be "wasteful"
Question B.
If I draw plain text onto a plain text memo/control/editor,
and manually draw string with manually calculated indentations, breaks, word wrappings to pretend the RTF.
Is it easier or harder?
Edited to make it look clearer
and sorry if my English looks like a student cause it's not my native language.
Sorry about my bad first attempt at an answer. I DID find an answer for measuring inside a RichTextBox. Apparently you have to use Win32 GDI API calls.
http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.framework.windowsforms.controls/2004-09/0574.html
I found this by changing my search after running across this nugget, which explains why there's not a pure .NET way to do it:
http://www.developmentnow.com/g/38_2005_10_0_0_626243/I-dont-believe-this-code-gives-the-correct-RichTextBox-string-size.htm

Categories

Resources