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