Italicizing characters in a RichTextBox - .net-3.0

I found how to make text bold in code:
richTextBox1.Rtf = #"{\rtf1\ansi This is in \b bold\b0.}";
But I also need how to make text italic. Google doesn't give me much.
I tried this (similar to bold, but with different character) but that doesn't work.
richTextBox1.Rtf = #"{\rtf1\ansi This is in \i italic\i0.}";
Can someone help me out please?

There are two articles that comes to my mind that may help you understand RTF, the first is a RTFTree which can be used to build a complex document and loads it akin to an XML document loading where you have trees/nodes. The other article is about writing your own RTF converter - a parser that can convert a RTF to HTML and vice versa.
You will find samples in the code on how to insert a italic formatting and so on. I included these two links to help give you insight into how to use RTF.
Begin Edit:
I have created a simple rtf document in WordPad as shown here
{\rtf1\ansi\ansicpg1252\deff0\deflang6153{\fonttbl{\f0\fswiss\fcharset0 Arial;}}
{\*\generator Msftedit 5.41.15.1515;}\viewkind4\uc1\pard\b\f0\fs20 Bold\b0\par
\i Italic\i0\par
}
The RTF document has two lines 'Bold' and 'Italic' with their respective formatting, saved the document and opened it up in another editor, that is what is shown. So something must be missing perhaps a paragraph marker \par wrapped around it.
This was done under Windows XP Home's WordPad.
End Edit
Hope these will be of help and use to you,
Best regards,
Tom.

this is how I managed to do it:
richTextBox1.Rtf = #"{\rtf1\ansi This is in \i\f0\fs17 italic\i0.}";
edit:
How did I do this?
I created a small test-application with a richtextbox and a button.
I typed some text in the richtextbox, I selected the text and pressed the button.
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.SelectionFont = new Font(richTextBox1.Font, FontStyle.Italic);
richTextBox1.SaveFile(#"c:\test.rtf");
}
This saved the rtf. I opened the rtf in Notepad++.
The content of the rtf was
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}
\viewkind4\uc1\pard\i\f0\fs17 hello\i00\par
}
and that's how I found how to use italics in a richtextbox.

Related

How to paste unformatted text in a xamarin forms editor view by code?

I'm working in a chords transposing app, It has an editor view for the user to paste the lyrics and chords. The problem is that when I hold tap in the entry view to paste the text, in some devices the lyric and chords appear in the same line, It seems It doesn't recognize the "\n" char in some lines from the web text. I've tried to use the clipboard like this:
if (Clipboard.HasText)
{
var textFromWeb = await Clipboard.GetTextAsync();
txtSongEntry.Text = textFromWeb;
}
It works, but like the first way, just works for some devices.
I've also tried to convert the clipboard text to utf8 but I get the same result.
In some devices there is a function called "paste as unformatted text", If I use this instead of simple paste It works perfect.
Is there any way to clean the clipboard text format before paste it on the editor?
All ideas/suggestion are welcome.
If I'm not clear let me know, English is not my native language :(

ckeditor soft return (shift-return) adds unknown character to HTML?

When using shift-return to add a soft return to ckeditor (version 4.5.3), and the resulting HTML is converted to PDF via wkhtmltopdf, there are "?" characters that are sometimes inserted at the start of the lines with soft returns.
Examining the HTML source, I find that there are 3 hidden characters inserted that wkhtmltopdf is converting to "?" since it doesn't know what to do with them. These characters don't show up in Notepad++ when "Show hidden characters" is turned on, but examining the file with a hex editor shows the are hex codes:
E2 80 8B
Why does ckeditor insert these hidden characters when you use a soft break, in addition to the <br /> tag? What is their purpose? And more importantly, is there a way I can disable this behavior? Or perhaps this is a bug?
UPDATE
I have duplicated the behavior using the current online ckeditor demo.
Type a few characters (like "asdf") on several lines, using shift-return to do a soft return between each line. Then click on the "Source" button to view the HTML. Select and copy an area large enough to more than fully contain the area you typed (make sure to copy a little extra below what you added). Then paste it into an online hex editor:
https://hexed.it/
You will see the same characters:
E2 80 8B
Please let me know if this is a bug. If not, what can I do to disable this behavior?
On the ckeditor bug report area, I was informed that the correct way to get "clean" HTML from ckeditor is to use:
editor.getData();
NOT what I was using:
editor.document.getBody().getHtml();
Posting here so others can easily find this, as the ckeditor documentation doesn't really help much.

Does an Indesign syntax highlighter exist?

Does anybody know of a non-manual method of highlighting syntax when pasted in InDesign?
I'm trying to show code of a project in an InDesign documentation but don't want to have to manually highlight the code, and preferably add numbered rows too.
Is there a plugin to achieve this?
This is the style in which I'd like to format the code.
Cheers
Not sure if you worked out an answer to this, but there's no magic button that will solve your problem.
However, InDesign does have a facility in each Paragraph style called GREP that can do what you're looking for.
This lets you write 'regex' or 'regular expressions' that are just rules for what to apply a given character style to. Yes, they look about as meaningful as Harry Potter incantations at first glance, but 2 or 3 simple regexes will get you a long way.
For instance:
(\<|<)!--\s*.*?\s*--(\>|>)
Will target HTML comments only.
(?<=").*?(?=")
This will target anything wrapped in straight double quotes.
(?<=\().*?(?=\))
This will target any text inside parentheses ().
There's an '#' symbol button in that GREP style next to where you type the regex - that gives you a drop-down menu that is almost like a 'Regex Wizard'. Try that too.
When you've got a regex that works, create a new character style for the text color and select it in the 'Apply Style' input.
Regexr.com has a tool that is good for testing this stuff. Paste your code sample in the bottom panel and your line of regex in the top. The bits that it targets will turn blue.
There is a searchable community panel on the left where people have probably already written expressions like the one you need.
I'm working out a JavaScript highlighter at the moment. It's a shame there's no communal 'Indesign style sharing library'.
Best of luck.
If had luck pasting syntax highlighted code into a Rich Text editor like Libre Office and then pasting it into Indesign. Just make sure whatever font your syntax highlighted code is in is also in InDesign because you'll get font missing errors when you pre-flight the book.

Text kerning in Microsoft rich text box

This one has me awfully confused...
I am trying to display kerned RTF text in a Visual Studio Visual Basic RichTextBox control (having so far tried under VS2010 and VS2012). Simply, I create a Windows Form project, add two RichTextBox's (RichTextBox1 and RichTextBox2) to the form, no change to default properties, and include the following VB code:
Public Class Form1
Private Sub Initialise(sender As System.Object, e As System.EventArgs) Handles Me.Load
Dim txtRTF As String = "{\rtf1\ansi" & _
"{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}}" & _
"\f0\pard" & _
"\expndtw-60 a" & _
"\expndtw200 b" & _
"\expndtw-20 c}"
RichTextBox1.Rtf = txtRTF
RichTextBox2.Paste() ' RichTextBox2 formats properly iff clipboard holds ANY valid rtf content
RichTextBox2.Rtf = txtRTF
End Sub
End Class
The txtRTF String contains, as best as I can tell, minimal valid RTF markup and text.
Here's the confusing bit: text displayed in RichTextBox1 is not kerned, despite \expndtw (expand twips) RTF markup, BUT text displayed in RichTextBox2 is properly kerned, if and only if the clipboard holds ANY valid RTF content (e.g., any text has first been copied into the clipboard from an MS Word document). Text displayed in RichTextBox2 is not properly kerned if clipboard contents is not RTF format.
Result of running if the clipboard does not contain RTF-formatted data (or if the RichTextBox2.Paste() code is removed or commented out):
Result of running if the clipboard holds any random RTF-formatted text:
Questions:
Why on earth should it matter that I have previously pasted RTF-format (and not non-RTF format) into the RichTextBox2 control before setting the RichTextBox2.Rtf field?
More importantly, how can I (in VB) programmatically display properly kerned text in a RichTextBox control without the absurdity of first pasting random RTF format text into it?
Well, that took a lot of work! Nevertheless, problem now solved.
It turns out that, although the RTF spec notes that \ltrch (left-to-right character run) is the default state, it seems that RichTextBox objects don't necessarily agree. Including a \ltrch (or even, oddly, a \rtlch) control sequence in the RTF markup stream completely solves the failure-to-kern problem. RTF text kerning via \expndtwN and \expndN now works perfectly well. No need for silly Paste() commands to pre-configure the RichTextBox control into its proper state!

How do I edit a text buffer (or selected text) with the Visual Studio 2010 SDK

I want to create a simple extension which modifies text buffers based on a command. No sample, documentation or template that I've found so far explains anything about working with text buffers. Anyone got a clue how to do this?
What I want to end up with is a format selection/document extension for text files, that wrap content around 72 characters per line.
I found this extension together with sample very helpful, and now I have something which works. Though it was very counter intuitive at first, I was trying to get the at the code window while this example instead uses a command filter to fiddle with the text view by extending the editor.
The ITextView interface provides access to the text in the editor, you can access the Buffer through that and make changes that way.
Link
http://github.com/noahric/alignassignments

Resources