programming4us
programming4us
MOBILE

Windows Phone 7 Development : Using a WebBrowser Control to Display Web Content

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
In the first of our WebBrowser walkthroughs, we will use this control to display the contents of the web site—we will show a list of photos of the best car in the world, the Lamborghini Gallardo.
  1. With the WebBrowser control in place, it's time to add some code to initialize its content when it loads work. First, right-click MainPage.xaml in Solution Explorer and select View Code (or go directly to the MainPage.xaml.cs file).

  2. Whenever the My Car Browser application loads the WebBrowser control, it fires off a Loaded event. By creating a Loaded event handler, you can write code to display a web page with car photos. Add the following code to the MainPage() constructor to create the handler:

    webBrowser1.Loaded += new RoutedEventHandler(webBrowser1_Loaded);

Notice how the same Visual Studio shortcuts we used for the Application Bar code apply here as well: namely, right after typing "+=" Visual Studio hints that if you press the Tab key twice, it will create all of the necessary code stubs you need for a handler.

  1. Next, let's code the event handler. To the webBrowser1_Loaded() function, add the following code, which will navigate to Microsoft Bing's image search page and pass the phrase "cars Lamborghini Gallardo" to it:

    webBrowser1.Navigate(newUri("http://www.bing.com/images/search?q=cars+Lamborghini+Gallardo"",
    UriKind.Absolute));


  2. This code creates a new Uri object and specifies that the Uri is not local to our application (that would be UriKind.Relative), but rather a location on the Internet (UriKind.Absolute).

Press F5 to debug your application and see the results so far. You should see photos of the most beautiful car in the world, courtesy of the Microsoft Bing engine. You can easily extend this example to respond to user input. For example, you could use the Bing image search to show photos of any car whose name a user enters. Here's how.

  1. Now let's add a text box to the page so the user can change the name of the car for which Bing searches. To do that, go to MainPage.xaml and display the page in the Designer (either by double-clicking MainPage.xaml or by right-clicking MainPage.xaml and selecting View Designer). If the Toolbox is not visible, go to View menu => Other Windows => Toolbox or click the Toolbox icon in the Visual Studio application bar. Click and drag the text box from the Toolbox, and position it below the WebBrowser control. Next, click and drag the Button, and position it next to the text box.

  2. Right-click the text box and select Properties. Delete everything from the Text property. Next, right-click the button and change the value of its Content property to "Show It!" (without the double quotes). The end result should resemble Figure 1.

  3. It's time to add some interactivity to our application. With MainPage.xaml still open in Designer view, double-click the button. Notice how the method button1_Click opens by default when you do that, ready for your code. Place the following code in the body of that method:

    webBrowser1.Navigate(new Uri
    ("http://www.bing.com/images/search?q=cars " + textBox1.Text,
    UriKind.Absolute));

  4. Press F5 to run the application. Initially, you should see the photos of the Lamborghini Gallardo added in the first part of this walkthrough. Go ahead and type "Ford Mustang" in the text box, and press the "Show It!" button. In the WebBrowser control, you should now see a set of photos of this great American muscle car.

    Figure 1. Adding a text box and a button to interact with the WebBrowser control

But there's more. You can also use a WebBrowser control to display HTML files—and even strings—that have been stored locally. We'll use that capability to add some Help to the Car Browser application in the next section.

Other  
  •  Windows Phone 7 Development : Adding a WebBrowser Control
  •  Programming the Mobile Web : Content Delivery (part 3)
  •  Programming the Mobile Web : Content Delivery (part 2) - File Delivery
  •  Programming the Mobile Web : Content Delivery (part 1) - Defining MIME Types
  •  iPhone Application Development : Using Switches, Segmented Controls, and Web Views (part 3)
  •  iPhone Application Development : Using Switches, Segmented Controls, and Web Views (part 2)
  •  iPhone Application Development : Using Switches, Segmented Controls, and Web Views (part 1)
  •  iPhone Application Development : Using Advanced Interface Objects and Views - User Input and Output
  •  Windows Phone 7 Development : Wiring Up Events to an Application Bar ( part 2)
  •  Windows Phone 7 Development : Wiring Up Events to an Application Bar ( part 1) - Reacting to Add Button Events
  •  
    Top 10
    Free Mobile And Desktop Apps For Accessing Restricted Websites
    MASERATI QUATTROPORTE; DIESEL : Lure of Italian limos
    TOYOTA CAMRY 2; 2.5 : Camry now more comely
    KIA SORENTO 2.2CRDi : Fuel-sipping slugger
    How To Setup, Password Protect & Encrypt Wireless Internet Connection
    Emulate And Run iPad Apps On Windows, Mac OS X & Linux With iPadian
    Backup & Restore Game Progress From Any Game With SaveGameProgress
    Generate A Facebook Timeline Cover Using A Free App
    New App for Women ‘Remix’ Offers Fashion Advice & Style Tips
    SG50 Ferrari F12berlinetta : Prancing Horse for Lion City's 50th
    - Messages forwarded by Outlook rule go nowhere
    - Create and Deploy Windows 7 Image
    - How do I check to see if my exchange 2003 is an open relay? (not using a open relay tester tool online, but on the console)
    - Creating and using an unencrypted cookie in ASP.NET
    - Directories
    - Poor Performance on Sharepoint 2010 Server
    - SBS 2008 ~ The e-mail alias already exists...
    - Public to Private IP - DNS Changes
    - Send Email from Winform application
    - How to create a .mdb file from ms sql server database.......
    programming4us programming4us
    programming4us
     
     
    programming4us