Using a WebBrowser Control to Display Local HTML Content in Office Word

Draw QR-Code in Office Word Using a WebBrowser Control to Display Local HTML Content

Using a WebBrowser Control to Display Local HTML Content
QR Code 2d Barcode Creation In None
Using Barcode creation for Office Word Control to generate, create QR-Code image in Office Word applications.
www.OnBarcode.com
Code 128C Maker In None
Using Barcode generation for Word Control to generate, create Code 128 Code Set B image in Office Word applications.
www.OnBarcode.com
Frequently, you will want to include documentation with your application to advertise its features to users and answer their most common questions. Because of its simplicity and ubiquity, HTML, the same language used to create web pages, has become the default format for such documentation. In this section, you ll create a simple HTML page describing how to work with the car photo application that you created in the previous section. Follow these steps to create and show HTML content on Windows Phone 7. 1. Because adding an HTML file is not an option on Windows Phone 7, you will need to add a new XML file to the project. XML files support automated syntax verification features, making it harder for you to make accidental mistakes. Right-click the WebBrowserSample project in the Solution Explorer and select Add New Item. Then, select XML File from the list of available item types.
Printing DataMatrix In None
Using Barcode generator for Office Word Control to generate, create Data Matrix image in Office Word applications.
www.OnBarcode.com
Draw PDF-417 2d Barcode In None
Using Barcode creator for Word Control to generate, create PDF 417 image in Word applications.
www.OnBarcode.com
CHAPTER 8 WEBBROWSER CONTROL
Barcode Creator In None
Using Barcode generation for Word Control to generate, create Barcode image in Office Word applications.
www.OnBarcode.com
Encode GTIN - 128 In None
Using Barcode printer for Microsoft Word Control to generate, create EAN128 image in Office Word applications.
www.OnBarcode.com
Type the following in the newly created file (you can also copy and paste this code from the files available for download for this book).
UPC-A Creation In None
Using Barcode creator for Office Word Control to generate, create GS1 - 12 image in Word applications.
www.OnBarcode.com
Generating ITF-14 In None
Using Barcode printer for Office Word Control to generate, create Case Code image in Office Word applications.
www.OnBarcode.com
<html> <title>Web Browser Help File</title> <body> <h1>Welcome to the Windows Phone 7 Car Browser Application! To view the car photos, type the name of the car in the textbox and press "Show It!" <br/><br/>For example, "Ford Mustang"</h1> </body> </html> 3. Save the file by pressing the Save button in Visual Studio. Next, right-click XMLFile1.xml in the Solution Explorer and click Rename. Change the name of that file to Help.htm and make sure that the Build action for that file is set to Content (by right-clicking and selecting Properties to bring up the Properties window). Now you will need to jump slightly ahead to the material covered in 13 (Isolated Storage). Here s why: while you would expect the Help.htm file to be automatically available to the application running on Windows Phone 7, it isn t. Before it is available to your application, the Help.htm file created in the previous step needs to be available to your application in the Isolated Storage, which you can think of as disk space reserved for use by your application on Windows Phone 7. As your application loads, you ll need to copy Help.htm to an Isolated Storage location first, and then retrieve it from there for display by the WebBrowser control. For the time being, simply add the following using directives to the top of the code page and then copy into your code the SaveHelpFileToIsoStore method shown in Listing 8 1.
Creating Quick Response Code In .NET Framework
Using Barcode maker for VS .NET Control to generate, create QR-Code image in Visual Studio .NET applications.
www.OnBarcode.com
Generate QR Code 2d Barcode In VS .NET
Using Barcode drawer for ASP.NET Control to generate, create QR Code 2d barcode image in ASP.NET applications.
www.OnBarcode.com
using System.IO.IsolatedStorage; using System.Windows.Resources; using System.IO; Listing 8 1. SaveHelpFiletoIsoStore Method private void SaveHelpFileToIsoStore() { string strFileName = "Help.htm"; IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication(); //remove the file if exists to allow each run to independently write to // the Isolated Storage if (isoStore.FileExists(strFileName) == true) { isoStore.DeleteFile(strFileName); } StreamResourceInfo sr = Application.GetResourceStream(new Uri(strFileName, UriKind.Relative)); using (BinaryReader br = new BinaryReader(sr.Stream)) { byte[] data = br.ReadBytes((int)sr.Stream.Length); //save file to Isolated Storage using (BinaryWriter bw = new BinaryWriter(isoStore.CreateFile(strFileName))) {
Create 1D In Java
Using Barcode drawer for Java Control to generate, create Linear Barcode image in Java applications.
www.OnBarcode.com
Code128 Creator In C#.NET
Using Barcode drawer for VS .NET Control to generate, create Code 128A image in .NET applications.
www.OnBarcode.com
CHAPTER 8 WEBBROWSER CONTROL
Print UPC-A Supplement 5 In None
Using Barcode generation for Software Control to generate, create UPC Symbol image in Software applications.
www.OnBarcode.com
Paint Linear In VS .NET
Using Barcode generator for ASP.NET Control to generate, create Linear Barcode image in ASP.NET applications.
www.OnBarcode.com
bw.Write(data); bw.Close(); } } } 5. Finally, you will invoke the SaveHelpFileToIsoStore method you wrote earlier to display the contents of Help.htm in the web browser when the browser first loads. Add the call to SaveHelpFileToIsoStore in the webBrowser1_Loaded method and set the webBrowser URL to navigate to the Help.htm file, as shown here:
Making Data Matrix 2d Barcode In C#.NET
Using Barcode generation for VS .NET Control to generate, create Data Matrix 2d barcode image in VS .NET applications.
www.OnBarcode.com
PDF417 Creator In .NET
Using Barcode drawer for ASP.NET Control to generate, create PDF 417 image in ASP.NET applications.
www.OnBarcode.com
void webBrowser1_Loaded(object sender, RoutedEventArgs e) { SaveHelpFileToIsoStore(); webBrowser1.Navigate(new Uri("Help.htm", UriKind.Relative)); }
PDF 417 Drawer In VS .NET
Using Barcode creator for Visual Studio .NET Control to generate, create PDF 417 image in Visual Studio .NET applications.
www.OnBarcode.com
Encode Matrix 2D Barcode In Visual Studio .NET
Using Barcode generation for .NET Control to generate, create Matrix image in .NET applications.
www.OnBarcode.com
Press F5 to run the application. You should see the simple HTML Help page displayed in the WebBrowser control.
Creating Code 128B In .NET Framework
Using Barcode generation for ASP.NET Control to generate, create Code 128C image in ASP.NET applications.
www.OnBarcode.com
Encoding ANSI/AIM Code 128 In None
Using Barcode maker for Software Control to generate, create USS Code 128 image in Software applications.
www.OnBarcode.com
In the next section, you will learn how to bypass Isolated Storage and show HTML generated directly by code.
Using a WebBrowser Control to Display Dynamic Content
Suppose now that the user enters Ford in the text box of the photo browsing application developed in the previous section. Unless you query the user, you won t know whether the user meant Ford Mustang or Ford F-150. One way to find out would be to create a page with HTML markup and display it to the user, asking for more information. You could then save the generated file to Isolated Storage, and load it using the technique described in the previous section (Using a WebBrowser Control to Display Local HTML Content). But that would certainly be a cumbersome approach for such a simple task. Luckily, there s a much easier way to show a dynamically generated HTML page: using the NavigateToString() method of the WebBrowser control. This method takes a single argument a string that contains all of the HTML needed to display the page you have in mind in the WebBrowser control. The next walkthrough shows just how easy it is to use this method. 1. Bring up the MainPage.xaml.cs file in the code editor (either by double-clicking it or clicking the MainPage.xaml file in the Solution Explorer and choosing View Code). Next, you will construct the HTML code to display to the user. Make the button1_Click method look identical to the following code notice how NavigateToString loads up what amounts to a basic HTML page directly into the WebBrowser control, without your having to save this HTML to the Isolated Storage. Also note that building an HTML string in code becomes a bit ugly very quickly, so NavigateToString should not be abused for large HTML messages/files.
Copyright © OnBarcode.com . All rights reserved.