Understanding RTF and edit it with vb.net - vb.net

I have this RichTextbox in my vb.net form and I would like to when a user click a button, for example to embold the selected text, how would I do this.
Also, I do NOT want to use the standard vb.net expressions such as RichTextBox1.SelectedText.Font.Bold = True. I want to do something like RichTextbox1.SelectedRTF="[bold]" & RichTextBox1.SelectedRTF & "[/bold]" or whatever RTF looks like.
Can I just add the RTF options random places or can a RichTextBox return an error if the text is in wrong format. I'm mostly looking for info on how to work with RTF without using the standard vb expressions. Thank you very much for any help provided

It just doesn't work this way, it is not an HTML editor. Hacking RTF directly is technically possible through the Rtf property but very hard to get right. RTF is not exactly a friendly format. Start reading here, try not to panic at the quality of that first page. Well, go ahead.

Related

Check if RichTextBox has formatting (vb.net)

Is there a way to detect if there is formatting or not (i.e. Rich) anywhere in a RichTextBox?
I'd like to write RichTextBox.Rtf is there is, and RichTextBox.Text if there isn't.
I came across a post that suggested checking the SelectionFont after selecting all text, but I have no idea how to accomplish that, or if it would work.
Thanks!
You can check the rtf property of the richtextbox: richtextbox1.rtfto see the rich text code. Even with no additional formatting, there will be some rich text formatting. For example, here's what you get with a richtextbox containing only "text":
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}
\viewkind4\uc1\pard\f0\fs16 test\par
}
You can check to see if there are any additional formatting tags, and if not, it should be plain text. You can also access the plain text (without formatting) with richtextbox1.text.

Finding specific letters in a text file and returning that as a string with my name to be placed in label control VB2010

I have a project where I have to find the letters of my name in a given text file in VB2010 and return those letters using string manipulation techniques as my name into a label control.
I have looked at several youtube videos and looked around the web. Some recommend putting the text file into an array. Some others are just for one specific word (Which my name isn't in the text file as a word). So I really haven't found anything to suit my needs.
I know the code needs to placed in the event load form.
I've only been at VB for 7 weeks, so I am novice.
Any tips or hints are appreciated. If further explanation needed please let me know.
Thanks,
Well, we won't do your homework for you, but here's a HOWTO on reading a text file in VB.NET. It's a good starting point.
How to: Read Text from a File
Look up regular expressions. This should help you with the parsing of the text file.

Creating RTF text for clipboard and sharing DataPackage in WinRT

I'm sure this is just a google search away, but I can't find the right search terms to find what I'm looking for.
I've created a DataPackage that has both HTML annd plain text content. I've used this in my copy and my sharing code and it works fine. I now want to create RTF output as some apps don't seem to accept HTML clipboard content.
I'm looking for a good guide to making RTF text that can be added to the DataPackage. I just need simple formatting including changing the font family, font size, font weight and adding newlines. The data comes from a list of objects taht I want to serialise as RTF, not from a text control on the screen.
WordPad outputs fairly clean RTF and some other text editors do as well. If that's not enough, you can download the RTF Specification 1.9.1 although like any specification that's probably overkill for what you're doing.
You can also use the SaveToStream method on the Document property of a RichEditBox from a Metro style app to share out as well.

Programatically extract content of PowerPoint slides into MS Word-like format?

I'd like to extract all of the information (formatted text, images, etc) from powerpoint slides into a flowing, readable (MS Word-style) format.
I'm not interested in keeping the slide concept at all--think of taking class slides from a college course and batch converting them all into one collective study guide.
I can't find a way to do this within powerpoint (though if you know of one, please share!) and,
I don't have experience scripting Office apps. Is this kind of thing easily done? Does this kind of script already exist somewhere?
Clarification:
In an earlier version of this post, I used the word "flowing" to refer to a slide-free (MS Word-like) format. This does not, however, refer to the actual formatting of slide content. So keeping bullet lists, etc. is fine and even desirable.
I don't see this being a simple task. College professors use a format of either "TITLE: BULLET POINTS OR IMAGE" or "EVERY WORD I'M ABOUT TO SAY" for their slides in my experience, and you're just not going to get flowing, readable text from the former no matter what you do. For the latter, you've already got your text, you just have to copy it to another document.
I think you might as well just open the PowerPoint, select all the text, and copy+paste into Word/Publisher/InDesign/your favorite page layout program. You'll have the same effect and the same amount of editing after the fact except without all the hassle of writing a program to do it for you.
Doing a Print operation to a PDF with the N-up options might be a good solution for handouts if that's all you need. You could expand the idea and condense ALL the slide decks into one, get it printed (with N slides per page and the note space next to it) and bound, and voila, instant study guide. I've seen that, and then you get options for note taking.
More power to you if you're doing this just because you can - don't let me stop you. There is much good learning to be had that way. You might want to look into writing a program using the Microsoft.Office.Interop namespace in .NET (starting at http://msdn.microsoft.com/en-us/library/bb772069.aspx ), or perhaps look on CPAN ( http://search.cpan.org/search?mode=all&query=powerpoint ) and do it with Perl! There are lots of ways to do it, but you've got to be up for the challenge.
Text is fairly simple to extract, but what text do you want? The text from the title and body text placeholders only? File, Save As, and choose to save the outline.
The other text on the slide? That can be pulled out to a text file programmatically, but in what order? Suppose you have a complex diagram with text callouts. Extracting the text is going to give you gibberish. There's no obvious/meaningful order to the text other than what the human viewer supplies by noting that "Ah. The arrow next to this bit of text points to the fribulator sub-assembly, so must relate to it in some way." Try doing that in code. ;-)
You could give the author a way to sort the text into reading order so that the code knows what order to extract it in, but that would require a fair amount of work on the part of the author.
If you can be certain that all of the content is in title+bullet form, no worries. Otherwise, you'd have to be able to articulate exactly what you want extracted, in what form and in what order before you could get anywhere with this.
MS Word-style is not only readable, but writeable as well (which was not specified in your requirements). If you want a read-only guide, PDF is your natural choice (either through Acrobat Distiller or LibreOffice). Combine individual Acrobatted presentations with PDFtk, or Acrobat or Foxit and you're good to go without any programming at all.
"Is this kind of thing easily done?" - Yes, your humble servant did a couple of similar scripts ages ago (extracting enhanced metafiles from Powerpoint slides).
"Does this kind of script already exist somewhere?" - Yes. Probably at hundreds of places, but not sure if any of them get posted to the 'Net. All things considered think you'd be better off learning some scripting and macro programming on your own, since a ready-made script may be not quite fit for your needs - and to understand and rewrite it you'd need more time than to code & debug from scratch.
Since you mention that title+bullet form is ok, open the file, choose to save as and pick Outline as the save-as type.
I think you could parse through the PowerPoint file for formatting, text and pictures. There are Visual Studio namespaces available for such a task. You open the file, parse through it and make Word file from these. Complicated work, as you would have to consider type of elements and their position, you would have to use a temporary structure for each slide.
Have a look at this sample code :
http://msdn.microsoft.com/en-us/library/office/gg278331.aspx
How to: Get All the Text in All Slides in a Presentation
Basically, using c# and openXML SDK 2.0, it loops through all the slides in the presentation, and then adds each text in every slide into a string builder. You can write out the result into a text file if you like (modification required).
Recommendation: <25 oct 2012>
For your study guide, maybe you could extract all the text in each slide, and dump those text programmatically (by adding that function into the sample code above while it's iterating the slides) into the "Notes" section of each slide. With that, you can print it in Notes Page view. You'll get the entire slide image at the top half of the page, and the actual slide texts at the bottom of it in the Notes Page view. It sure beats trying to copy and paste all the text from the slide into the notes section. You can even print it 2 slides per page, as small text would not be an issue inside the slide's image, and diagrams would still be visible more or less.
Unfortunatly, this method works for simple standard slide format ... meaning, it's OK if your slides just have a title, and a center text box with all the bullet points... any complex slide layout (maybe text boxes scattered everywhere) will come out in non-order and will be confusing. But at least you can still look at the slide image above to make sense of it :)

Silverlight 4 RichtTextBox - how do I get the text without the formatting?

How do I get the text out of a Silverlight 4 RichTextBox without the formatting? I know the Xaml property will give me the XAML but I just want the text.
This is a little late, but I will post anyway. There is a trick that involves selecting all the text in code and then accessing the Text propety of the TextSelection object. Like so:
myRichTextBox.SelectAll();
var plainText = myRichTextBox.Selection.Text;
I am using it in my apps and although it is not the prettiest solution, it works. Found it here:
http://forums.silverlight.net/forums/p/184560/422007.aspx
If you just want text, why not use TextBox instead?
There are various third-party components that support this kind of functionality (unfortunately paid). For example, Telerik's RadRichTextBox supports both highlighting and exporting rich text content as plain text, latter trough component called TxtFormatProvider.