In a , you can load an RTF or an HTML file into the RichTextBox control both at design time and at run time . Following is a step-by-step process that helps you load these files into the RichTextBox control.
These steps assume that you have already added a Section Report (code based) template in a Visual Studio project and have placed a RichTextBox control inside its section. See Adding an ActiveReport to a Project for more information.
|
Caution: Do not attempt to load a file into a RichTextBox in a section that repeats. After the first iteration of the section, the RTF or HTML file is already in use by that first iteration and returns "file in use" errors when that section is processed again. |
To write an RTF file to load into a RichTextBox control
- Open wordpad, and paste the following formatted text into it.
Paste into an RTF File
Customer List by Country
Argentina
- Rancho grande
- Océano Atlántico Ltda.
- Cactus Comidas para llevar
Austria
- Piccolo und mehr
- Ernst Handel
Belgium
- Suprêmes délices
- Maison Dewey
Brazil
- Familia Arquibaldo
- Wellington Improtadora
- Que Delícia
- Tradição Hipermercados
- Ricardo Adocicados
- Hanari Carnes
- Queen Cozinha
- Comércio Mineiro
- Gourmet Lanchonetes
- Save the file as sample.rtf in the debug directory inside the bin folder of your project.
|
Note: The RichTextBox control is limited in its support for advanced RTF features such as the ones supported by Microsoft Word. In general, the features supported by WordPad are supported in this control. |
To load an RTF file into the RichTextBox control at design time
- On the report , add a RichTextBox control.
- With the RichTextBox control selected, at the botton of the Properties Window, click the Load File command. See Properties Window for a description of commands.
- In the Open dialog that appears, browse to an *.RTF file (For example, sample.rtf) and click the Open button to load the file in the RichTextBox control.
To load an RTF file into the RichTextBox control at run time
|
Note: The RichTextBox control has limited support for advanced RTF features such as the ones supported by Microsoft Word. Therefore, use a WordPad for obtaining best results. |
These steps assume that the RTF file (for example, sample.rtf) to load has been saved in the bin/debug directory of your project.
- Right-click the report and select View Code to open the code view.
- Add an Imports (Visual Basic.NET) or using (C#) statement at the top of the code view for the GrapeCity.ActiveReports.SectionReportModel namespace.
- In the design view, double-click the section of the report to create an event-handling method for the Detail Format event.
- Add the following code to the handler to load the RTF file into the RichTextBox control.
The following example shows what the code for the method looks like.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the Detail1_Format event. |
Copy Code
|
Dim streamRTF As New System.IO.FileStream(System.Windows.Forms.Application.StartupPath + "\sample.rtf", System.IO.FileMode.Open) Me.RichTextBox1.Load(streamRTF, RichTextType.Rtf)
|
To write the code in C#
C# code. Paste INSIDE the detail_Format event. |
Copy Code
|
System.IO.FileStream streamRTF = new System.IO.FileStream(System.Windows.Forms.Application.StartupPath + "\\sample.rtf", System.IO.FileMode.Open);
this.richTextBox1.Load(streamRTF, RichTextType.Rtf);
|
|
Note: The Application.Startup path code does not work in preview mode. You must run the project in order to see the file load. |
To write an HTML file to load into a RichTextBox control
- Open a Notepad, and paste the following HTML code into it.
HTML code
HTML code. Paste in a NotePad file. |
Copy Code
|
<html>
<body>
<center><h1>Customer List by Country</h1></center>
<h1>Argentina</h1>
<ul>
<li>Rancho grande
<li>Océano Atlántico Ltda.
<li>Cactus Comidas para llevar
</ul>
<h1>Austria</h1>
<ul>
<li>Piccolo und mehr
<li>Ernst Handel
</ul>
<h1>Belgium</h1>
<ul>
<li>Suprêmes délices
<li>Maison Dewey
</ul>
<h1>Brazil</h1>
<ul>
<li>Familia Arquibaldo
<li>Wellington Improtadora
<li>Que Delícia
<li>Tradição Hipermercados
<li>Ricardo Adocicados
<li>Hanari Carnes
<li>Queen Cozinha
<li>Comércio Mineiro
<li>Gourmet Lanchonetes
</ul>
</body>
</html>
|
- Save the file as sample.html.
To load an HTML file into the RichTextBox control at design time
- On the report , add a RichTextBox control.
- With the RichTextBox control selected, at the bottom of the Properties Window, click the Load File command. See Properties Window for a description of commands.
- In the Open dialog that appears, browse to an *.html file (For example, sample.html) and click the Open button to load the file in the RichTextBox control.
To load an HTML file into a RichTextBox control at run time
These steps assume that the HTML file (for example, sample.html) to load has been saved in the bin/debug directory of your project.
- Right-click the report and select View Code to open the code view.
- Add an Imports (Visual Basic.NET) or using (C#) statement at the top of the code view for the GrapeCity.ActiveReports.SectionReportModel namespace.
- In the design view, double-click the section of the report to create an event-handling method for the Detail Format event.
- Add code to the handler to load the HTML file into the RichText control.
The following example shows what the code for the method looks like.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the Detail1_Format event. |
Copy Code
|
Dim streamHTML As New System.IO.FileStream(System.Windows.Forms.Application.StartupPath + "\sample.HTML", System.IO.FileMode.Open) Me.RichTextBox1.Load(streamHTML, RichTextType.Html)
|
To write the code in C#
C# code. Paste INSIDE the detail_Format event. |
Copy Code
|
System.IO.FileStream streamHTML = new System.IO.FileStream(System.Windows.Forms.Application.StartupPath + "\\sample.html", System.IO.FileMode.Open);
this.richTextBox1.Load(streamHTML, RichTextType.Html); |
|
Note: The Application.Startup path code does not work in preview mode. You must run the project in order to see the file load. |
See Also