PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/Visual Studio 2008/CSWebBrowserWithProxy/MainForm.cs

#
C# | 91 lines | 56 code | 12 blank | 23 comment | 1 complexity | e239d7ba7cb34489242b2a24741c19cf MD5 | raw file
 1/****************************** Module Header ******************************\
 2 Module Name:  MainForm.cs
 3 Project:      CSWebBrowserWithProxy
 4 Copyright (c) Microsoft Corporation.
 5 
 6 This is the main form of this application. It is used to initialize the UI and 
 7 handle the events.
 8 
 9 This source is subject to the Microsoft Public License.
10 See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
11 All other rights reserved.
12 
13 THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
14 EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
15 WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
16\***************************************************************************/
17
18
19using System;
20using System.Windows.Forms;
21using System.Security.Permissions;
22
23namespace CSWebBrowserWithProxy
24{
25
26    public partial class MainForm : Form
27    {
28        // Get the current proxy.
29        InternetProxy CurrentProxy
30        {
31            get
32            {
33                if (radIEProxy.Checked)
34                {
35                    return InternetProxy.NoProxy;
36                }
37                else
38                {
39                    return cmbProxy.SelectedItem as InternetProxy;
40                }
41            }
42        }
43
44        [PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
45        public MainForm()
46        {
47            InitializeComponent();
48        }
49
50        private void MainForm_Load(object sender, EventArgs e)
51        {
52
53            // Data bind cmbProxy to display the ProxyList.
54            cmbProxy.DisplayMember = "ProxyName";
55            cmbProxy.DataSource = InternetProxy.ProxyList;
56            cmbProxy.SelectedIndex = 0;
57
58            wbcSample.StatusTextChanged += new EventHandler(wbcSample_StatusTextChanged);
59
60        }
61
62        /// <summary>
63        /// Handle btnNavigate_Click event.
64        /// The method Goto of WebBrowserControl class wraps the Navigate method of
65        /// WebBrowser class to set the Proxy-Authorization header if needed.
66        /// </summary>
67        private void btnNavigate_Click(object sender, EventArgs e)
68        {
69            try
70            {
71                wbcSample.Proxy = CurrentProxy;
72                wbcSample.Goto(tbUrl.Text);
73            }
74            catch (ArgumentException)
75            {
76                MessageBox.Show("Please maske sure that the url is valid.");
77            }
78        }
79
80        private void wbcSample_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
81        {
82            prgBrowserProcess.Value = (int)e.CurrentProgress;
83            wbcSample.StatusTextChanged += new EventHandler(wbcSample_StatusTextChanged);
84        }
85
86        void wbcSample_StatusTextChanged(object sender, EventArgs e)
87        {
88            lbStatus.Text = wbcSample.StatusText;
89        }
90    }
91}