Sunday, June 5, 2016

Lesson 5: Windows phone Application: Creating Web Browser

1.     On the menu bar, choose File, New, and Project.
2.  Choose Programming language as  Visual C# . In the templates list, choose the Windows Phone  and then choose Windows Phone App.
3. Name the project as MiniWebBrowser and specify the address of your folder.

4. In the design window of the page design as shown below.

Mini Web Browser

   The controls used on the above image are given below. the properties of the      controls  also set   accordingly.
    i. TextBlock Name=StackPanelTextBlock1     and
Text=Mini Web Browser Application

   ii. TextBlock Name=StackPanelTextBlock2     and
Text=Home Page

   iii. TextBox Name=txtUrl
Text=http://www.

   iv. WebBrowser Name=wb1

   v. Button Name=btnGo 
Content=Go

   5. Add the following statement(namespace) in the code area.
                  using System.Text.RegularExpressions;
   6. Double click the Go button , corresponding MiniWebBrowser.xaml.cs      
        window will be opened . Type the following code.  
      
       private void btnGo_Click(object sender, RoutedEventArgs e)
        {
            string url = txtUrl.Text;
            string urlPattern = @"^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$";
            if (Regex.IsMatch(url, urlPattern))
            {
                wb1.Navigate(new Uri(url, UriKind.RelativeOrAbsolute));
            }
            else
            {
                MessageBox.Show("Not a valid url");
            }
        }
   7.  Run the App and see the result.






No comments:

Post a Comment