[Sample of June 19th] XML syntax highlighting in RichTextBox

 

Homepage image
image RSS Feed

Sample Download : https://code.msdn.microsoft.com/VBRichTextBoxSyntaxHighligh-d73c7c4c  

The sample demonstrates how to format XML and highlight the elements in RichTextBoxControl.

RichTextBoxControl can process RTF(Rich Text Format) file, which is a proprietary document file format with published specification developed by Microsoft Corporation.

A simple RTF file is like

{\rtf1\ansi\ansicpg1252\deff0\deflang1033\deflangfe2052
{\fonttbl{\f0\fnil Courier New;}}
{\colortbl ;\red0\green0\blue255;\red139\green0\blue0;\red255\green0\blue0;\red0\green0\blue0;}
\viewkind4\uc1\pard\cf1\f0\fs24
< ?\cf2 xml \cf3 version\cf1 =\cf0 "\cf1 1.0\cf0 " \cf3 encoding\cf1 =\cf0 "\cf1 utf-8\cf0 "\cf1 ?>\par
< \cf2 html\cf1 >\par
   <\cf2 head\cf1 >\par
       <\cf2 title\cf1 >\par
           \cf4 My home page\par
       \cf1 </\cf2 title\cf1 >\par
   </\cf2 head\cf1 >\par
   <\cf2 body \cf3 bgcolor\cf1 =\cf0 "\cf1 000000\cf0 " \cf3 text\cf1 =\cf0 "\cf1 ff0000\cf0 " \cf1 >\par
       \cf4 Hello World!\par
   \cf1 </\cf2 body\cf1 >\par
< /\cf2 html\cf1 >\par
}

It contains 2 parts:Header and Content.The colortbl in header includes all the color definitions used in the file. \cfN means the Foreground color and \par means a new paragraph.

image

 

imageYou can find more code samples that demonstrate the most typical programming scenarios by using Microsoft All-In-One Code Framework Sample Browser or Sample Browser Visual Studio extension. They give you the flexibility to search samples, download samples on demand, manage the downloaded samples in a centralized place, and automatically be notified about sample updates. If it is the first time that you hear about Microsoft All-In-One Code Framework, please watch the introduction video on Microsoft Showcase, or read the introduction on our homepage https://1code.codeplex.com/.