Back to index

lightning-sunbird  0.9+nobinonly
Form1.cs
Go to the documentation of this file.
00001 using System;
00002 using System.Drawing;
00003 using System.Collections;
00004 using System.ComponentModel;
00005 using System.Windows.Forms;
00006 using System.Data;
00007 
00008 namespace CSBrowse
00009 {
00013        public class Form1 : System.Windows.Forms.Form
00014        {
00015               private AxMOZILLACONTROLLib.AxMozillaBrowser axMozillaBrowser1;
00016               private System.Windows.Forms.StatusBar statusBar1;
00017               private System.Windows.Forms.Button goBtn;
00018               private System.Windows.Forms.StatusBarPanel statusMessagePane;
00019               private System.Windows.Forms.ToolBar toolBar1;
00020               private System.Windows.Forms.ToolBarButton btnBack;
00021               private System.Windows.Forms.ToolBarButton btnForward;
00022               private System.Windows.Forms.StatusBarPanel statusProgressPane;
00023               private System.Windows.Forms.ImageList imageList1;
00024               private System.Windows.Forms.ToolBarButton btnSep1;
00025               private System.Windows.Forms.ToolBarButton btnStop;
00026               private System.Windows.Forms.ToolBarButton btnReload;
00027               private System.Windows.Forms.ToolBarButton btnHome;
00028               private System.Windows.Forms.MainMenu mainMenu1;
00029               private System.Windows.Forms.MenuItem menuItem1;
00030               private System.Windows.Forms.MenuItem menuExit;
00031               private System.Windows.Forms.MenuItem menuItem2;
00032               private System.Windows.Forms.MenuItem menuAbout;
00033               private System.Windows.Forms.ComboBox url;
00034               private System.Windows.Forms.ToolBarButton btnSep2;
00035               private System.ComponentModel.IContainer components;
00036 
00037               public Form1()
00038               {
00039                      //
00040                      // Required for Windows Form Designer support
00041                      //
00042                      InitializeComponent();
00043 
00044                      //
00045                      // TODO: Add any constructor code after InitializeComponent call
00046                      //
00047               }
00048 
00052               protected override void Dispose( bool disposing )
00053               {
00054                      if( disposing )
00055                      {
00056                             if (components != null) 
00057                             {
00058                                    components.Dispose();
00059                             }
00060                      }
00061                      base.Dispose( disposing );
00062               }
00063 
00064               #region Windows Form Designer generated code
00065 
00066 
00067 
00068 
00069               private void InitializeComponent()
00070               {
00071                      this.components = new System.ComponentModel.Container();
00072                      System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
00073                      this.axMozillaBrowser1 = new AxMOZILLACONTROLLib.AxMozillaBrowser();
00074                      this.goBtn = new System.Windows.Forms.Button();
00075                      this.statusBar1 = new System.Windows.Forms.StatusBar();
00076                      this.statusMessagePane = new System.Windows.Forms.StatusBarPanel();
00077                      this.statusProgressPane = new System.Windows.Forms.StatusBarPanel();
00078                      this.toolBar1 = new System.Windows.Forms.ToolBar();
00079                      this.btnBack = new System.Windows.Forms.ToolBarButton();
00080                      this.btnForward = new System.Windows.Forms.ToolBarButton();
00081                      this.btnSep1 = new System.Windows.Forms.ToolBarButton();
00082                      this.btnStop = new System.Windows.Forms.ToolBarButton();
00083                      this.btnReload = new System.Windows.Forms.ToolBarButton();
00084                      this.btnHome = new System.Windows.Forms.ToolBarButton();
00085                      this.imageList1 = new System.Windows.Forms.ImageList(this.components);
00086                      this.mainMenu1 = new System.Windows.Forms.MainMenu();
00087                      this.menuItem1 = new System.Windows.Forms.MenuItem();
00088                      this.menuExit = new System.Windows.Forms.MenuItem();
00089                      this.menuItem2 = new System.Windows.Forms.MenuItem();
00090                      this.menuAbout = new System.Windows.Forms.MenuItem();
00091                      this.url = new System.Windows.Forms.ComboBox();
00092                      this.btnSep2 = new System.Windows.Forms.ToolBarButton();
00093                      ((System.ComponentModel.ISupportInitialize)(this.axMozillaBrowser1)).BeginInit();
00094                      ((System.ComponentModel.ISupportInitialize)(this.statusMessagePane)).BeginInit();
00095                      ((System.ComponentModel.ISupportInitialize)(this.statusProgressPane)).BeginInit();
00096                      this.SuspendLayout();
00097                      // 
00098                      // axMozillaBrowser1
00099                      // 
00100                      this.axMozillaBrowser1.Enabled = true;
00101                      this.axMozillaBrowser1.Location = new System.Drawing.Point(24, 112);
00102                      this.axMozillaBrowser1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axMozillaBrowser1.OcxState")));
00103                      this.axMozillaBrowser1.Size = new System.Drawing.Size(640, 400);
00104                      this.axMozillaBrowser1.TabIndex = 3;
00105                      this.axMozillaBrowser1.DownloadComplete += new System.EventHandler(this.axMozillaBrowser1_DownloadComplete);
00106                      this.axMozillaBrowser1.StatusTextChange += new AxMOZILLACONTROLLib.DWebBrowserEvents2_StatusTextChangeEventHandler(this.axMozillaBrowser1_StatusTextChange);
00107                      this.axMozillaBrowser1.NavigateComplete2 += new AxMOZILLACONTROLLib.DWebBrowserEvents2_NavigateComplete2EventHandler(this.axMozillaBrowser1_NavigateComplete2);
00108                      this.axMozillaBrowser1.CommandStateChange += new AxMOZILLACONTROLLib.DWebBrowserEvents2_CommandStateChangeEventHandler(this.axMozillaBrowser1_CommandStateChange);
00109                      this.axMozillaBrowser1.LocationChanged += new System.EventHandler(this.axMozillaBrowser1_LocationChanged);
00110                      this.axMozillaBrowser1.BeforeNavigate2 += new AxMOZILLACONTROLLib.DWebBrowserEvents2_BeforeNavigate2EventHandler(this.axMozillaBrowser1_BeforeNavigate2);
00111                      this.axMozillaBrowser1.NewWindow2 += new AxMOZILLACONTROLLib.DWebBrowserEvents2_NewWindow2EventHandler(this.axMozillaBrowser1_NewWindow2);
00112                      this.axMozillaBrowser1.DownloadBegin += new System.EventHandler(this.axMozillaBrowser1_DownloadBegin);
00113                      // 
00114                      // goBtn
00115                      // 
00116                      this.goBtn.Location = new System.Drawing.Point(616, 72);
00117                      this.goBtn.Name = "goBtn";
00118                      this.goBtn.Size = new System.Drawing.Size(48, 21);
00119                      this.goBtn.TabIndex = 4;
00120                      this.goBtn.Text = "Go";
00121                      this.goBtn.Click += new System.EventHandler(this.button1_Click);
00122                      // 
00123                      // statusBar1
00124                      // 
00125                      this.statusBar1.Location = new System.Drawing.Point(0, 539);
00126                      this.statusBar1.Name = "statusBar1";
00127                      this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
00128                                                                                                                                                             this.statusMessagePane,
00129                                                                                                                                                             this.statusProgressPane});
00130                      this.statusBar1.ShowPanels = true;
00131                      this.statusBar1.Size = new System.Drawing.Size(696, 22);
00132                      this.statusBar1.TabIndex = 5;
00133                      this.statusBar1.PanelClick += new System.Windows.Forms.StatusBarPanelClickEventHandler(this.statusBar1_PanelClick);
00134                      this.statusBar1.DrawItem += new System.Windows.Forms.StatusBarDrawItemEventHandler(this.statusBar1_DrawItem);
00135                      // 
00136                      // statusMessagePane
00137                      // 
00138                      this.statusMessagePane.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
00139                      this.statusMessagePane.BorderStyle = System.Windows.Forms.StatusBarPanelBorderStyle.None;
00140                      this.statusMessagePane.Width = 580;
00141                      // 
00142                      // statusProgressPane
00143                      // 
00144                      this.statusProgressPane.Style = System.Windows.Forms.StatusBarPanelStyle.OwnerDraw;
00145                      this.statusProgressPane.Text = "statusBarPanel1";
00146                      // 
00147                      // toolBar1
00148                      // 
00149                      this.toolBar1.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
00150                      this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
00151                                                                                                                                                           this.btnBack,
00152                                                                                                                                                           this.btnForward,
00153                                                                                                                                                           this.btnSep1,
00154                                                                                                                                                           this.btnReload,
00155                                                                                                                                                           this.btnStop,
00156                                                                                                                                                           this.btnSep2,
00157                                                                                                                                                           this.btnHome});
00158                      this.toolBar1.ButtonSize = new System.Drawing.Size(32, 32);
00159                      this.toolBar1.DropDownArrows = true;
00160                      this.toolBar1.ImageList = this.imageList1;
00161                      this.toolBar1.Name = "toolBar1";
00162                      this.toolBar1.ShowToolTips = true;
00163                      this.toolBar1.Size = new System.Drawing.Size(696, 55);
00164                      this.toolBar1.TabIndex = 6;
00165                      this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
00166                      // 
00167                      // btnBack
00168                      // 
00169                      this.btnBack.Enabled = false;
00170                      this.btnBack.ImageIndex = 0;
00171                      this.btnBack.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton;
00172                      this.btnBack.Tag = "Back";
00173                      this.btnBack.Text = "Back";
00174                      this.btnBack.ToolTipText = "Back one page";
00175                      // 
00176                      // btnForward
00177                      // 
00178                      this.btnForward.Enabled = false;
00179                      this.btnForward.ImageIndex = 1;
00180                      this.btnForward.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton;
00181                      this.btnForward.Text = "Forward";
00182                      this.btnForward.ToolTipText = "Forward one page";
00183                      // 
00184                      // btnSep1
00185                      // 
00186                      this.btnSep1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
00187                      // 
00188                      // btnStop
00189                      // 
00190                      this.btnStop.Enabled = false;
00191                      this.btnStop.ImageIndex = 4;
00192                      this.btnStop.Text = "Stop";
00193                      this.btnStop.ToolTipText = "Stop loading";
00194                      // 
00195                      // btnReload
00196                      // 
00197                      this.btnReload.ImageIndex = 3;
00198                      this.btnReload.Text = "Reload";
00199                      this.btnReload.ToolTipText = "Reload this page";
00200                      // 
00201                      // btnHome
00202                      // 
00203                      this.btnHome.ImageIndex = 2;
00204                      this.btnHome.Text = "Home";
00205                      this.btnHome.ToolTipText = "Go Home";
00206                      // 
00207                      // imageList1
00208                      // 
00209                      this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
00210                      this.imageList1.ImageSize = new System.Drawing.Size(32, 32);
00211                      this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
00212                      this.imageList1.TransparentColor = System.Drawing.Color.Black;
00213                      // 
00214                      // mainMenu1
00215                      // 
00216                      this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
00217                                                                                                                                                      this.menuItem1,
00218                                                                                                                                                      this.menuItem2});
00219                      // 
00220                      // menuItem1
00221                      // 
00222                      this.menuItem1.Index = 0;
00223                      this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
00224                                                                                                                                                      this.menuExit});
00225                      this.menuItem1.Text = "&File";
00226                      // 
00227                      // menuExit
00228                      // 
00229                      this.menuExit.Index = 0;
00230                      this.menuExit.Text = "E&xit";
00231                      this.menuExit.Click += new System.EventHandler(this.menuExit_Click);
00232                      // 
00233                      // menuItem2
00234                      // 
00235                      this.menuItem2.Index = 1;
00236                      this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
00237                                                                                                                                                      this.menuAbout});
00238                      this.menuItem2.Text = "&Help";
00239                      // 
00240                      // menuAbout
00241                      // 
00242                      this.menuAbout.Index = 0;
00243                      this.menuAbout.Text = "&About...";
00244                      this.menuAbout.Click += new System.EventHandler(this.menuAbout_Click);
00245                      // 
00246                      // url
00247                      // 
00248                      this.url.Items.AddRange(new object[] {
00249                                                                                             "http://127.0.0.1/",
00250                                                                                             "http://127.0.0.1:8080/",
00251                                                                                             "http://www.mozilla.org/",
00252                                                                                             "http://www.cnn.com/",
00253                                                                                             "http://www.yahoo.com/",
00254                                                                                             "http://www.slashdot.org/",
00255                                                                                             "http://www.amazon.com/"});
00256                      this.url.Location = new System.Drawing.Point(24, 72);
00257                      this.url.MaxLength = 1024;
00258                      this.url.Name = "url";
00259                      this.url.Size = new System.Drawing.Size(568, 21);
00260                      this.url.TabIndex = 0;
00261                      // 
00262                      // btnSep2
00263                      // 
00264                      this.btnSep2.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
00265                      // 
00266                      // Form1
00267                      // 
00268                      this.AcceptButton = this.goBtn;
00269                      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
00270                      this.ClientSize = new System.Drawing.Size(696, 561);
00271                      this.Controls.AddRange(new System.Windows.Forms.Control[] {
00272                                                                                                                                 this.url,
00273                                                                                                                                 this.toolBar1,
00274                                                                                                                                 this.statusBar1,
00275                                                                                                                                 this.goBtn,
00276                                                                                                                                 this.axMozillaBrowser1});
00277                      this.Menu = this.mainMenu1;
00278                      this.Name = "Form1";
00279                      this.Text = "CSBrowse";
00280                      this.Load += new System.EventHandler(this.Form1_Load);
00281                      this.Layout += new System.Windows.Forms.LayoutEventHandler(this.Form1_Layout);
00282                      ((System.ComponentModel.ISupportInitialize)(this.axMozillaBrowser1)).EndInit();
00283                      ((System.ComponentModel.ISupportInitialize)(this.statusMessagePane)).EndInit();
00284                      ((System.ComponentModel.ISupportInitialize)(this.statusProgressPane)).EndInit();
00285                      this.ResumeLayout(false);
00286 
00287               }
00288               #endregion
00289 
00293               [STAThread]
00294               static void Main() 
00295               {
00296                      Application.Run(new Form1());
00297               }
00298 
00299               private void Form1_Load(object sender, System.EventArgs e)
00300               {
00301                             
00302               }
00303 
00304               private void button1_Click(object sender, System.EventArgs e)
00305               {
00306                      object n = null;
00307                      axMozillaBrowser1.Navigate(url.Text, ref n, ref n, ref n, ref n);
00308               }
00309 
00310               private void statusBar1_PanelClick(object sender, System.Windows.Forms.StatusBarPanelClickEventArgs e)
00311               {
00312               
00313               }
00314               
00315               private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
00316               {
00317                      if (e.Button.Equals(btnBack))
00318                      {
00319                             axMozillaBrowser1.GoBack();
00320                      }
00321                      else if (e.Button.Equals(btnForward))
00322                      {
00323                             axMozillaBrowser1.GoForward();
00324                      }
00325                      else if (e.Button.Equals(btnStop))
00326                      {
00327                             axMozillaBrowser1.Stop();
00328                      }
00329                      else if (e.Button.Equals(btnReload))
00330                      {
00331                             axMozillaBrowser1.Refresh();
00332                      }
00333                      else if (e.Button.Equals(btnHome))
00334                      {
00335                             axMozillaBrowser1.GoHome();
00336                      }
00337               }
00338 
00339               private void statusBar1_DrawItem(object sender, System.Windows.Forms.StatusBarDrawItemEventArgs sbdevent)
00340               {
00341                      if (sbdevent.Panel.Equals(statusProgressPane))
00342                      {
00343 
00344                      }
00345               }
00346 
00347               private void axMozillaBrowser1_StatusTextChange(object sender, AxMOZILLACONTROLLib.DWebBrowserEvents2_StatusTextChangeEvent e)
00348               {
00349                      statusMessagePane.Text = e.text;
00350               }
00351 
00352               private void axMozillaBrowser1_CommandStateChange(object sender, AxMOZILLACONTROLLib.DWebBrowserEvents2_CommandStateChangeEvent e)
00353               {
00354                      if ((e.command & 0x1) != 0) // Forward
00355                      {
00356                             btnForward.Enabled = e.enable;
00357                      }
00358                      if ((e.command & 0x2) != 0) // Backward
00359                      {
00360                             btnBack.Enabled = e.enable;
00361                      }
00362               }
00363 
00364               private void axMozillaBrowser1_NewWindow2(object sender, AxMOZILLACONTROLLib.DWebBrowserEvents2_NewWindow2Event e)
00365               {
00366                      Form1 f = new Form1();
00367                      f.Show();
00368                      object n = null;
00369                      f.axMozillaBrowser1.Navigate("about:blank", ref n, ref n, ref n, ref n);
00370                      e.ppDisp = f.axMozillaBrowser1.Application;
00371               }
00372 
00373               private void axMozillaBrowser1_DownloadBegin(object sender, System.EventArgs e)
00374               {
00375                      btnStop.Enabled = true;
00376               }
00377 
00378               private void axMozillaBrowser1_DownloadComplete(object sender, System.EventArgs e)
00379               {
00380                      btnStop.Enabled = false;
00381               }
00382 
00383               private void axMozillaBrowser1_BeforeNavigate2(object sender, AxMOZILLACONTROLLib.DWebBrowserEvents2_BeforeNavigate2Event e)
00384               {
00385               }
00386 
00387               private void axMozillaBrowser1_NavigateComplete2(object sender, AxMOZILLACONTROLLib.DWebBrowserEvents2_NavigateComplete2Event e)
00388               {
00389                      this.Text = axMozillaBrowser1.LocationName + " - CSBrowse";
00390                      url.Text = axMozillaBrowser1.LocationURL;
00391               }
00392 
00393               private void axMozillaBrowser1_LocationChanged(object sender, System.EventArgs e)
00394               {
00395                      url.Text = axMozillaBrowser1.LocationURL;
00396               }
00397 
00398               private void Form1_Layout(object sender, System.Windows.Forms.LayoutEventArgs e)
00399               {
00400                      // Resize the browser to fit the new available space
00401                      toolBar1.Location =
00402                             new Point(this.ClientRectangle.Left, this.ClientRectangle.Top);
00403                      
00404                      goBtn.Location = new Point(
00405                             this.ClientRectangle.Right - goBtn.Width,
00406                             toolBar1.Left + toolBar1.Height);
00407                      
00408                      url.Location = new Point(
00409                             this.ClientRectangle.Left,
00410                             toolBar1.Left + toolBar1.Height);
00411                      url.Size = new Size(
00412                             goBtn.Left - url.Left, goBtn.Height);
00413 
00414                      statusBar1.Location = new Point(
00415                             this.ClientRectangle.Left,
00416                             this.ClientRectangle.Bottom - statusBar1.Height);
00417 
00418                      axMozillaBrowser1.Location = new Point(
00419                             this.ClientRectangle.Left, url.Bottom);
00420                      axMozillaBrowser1.Size = new Size(
00421                             this.ClientSize.Width,
00422                             statusBar1.Top - axMozillaBrowser1.Top);
00423               }
00424 
00425               private void url_TextChanged(object sender, System.EventArgs e)
00426               {
00427               
00428               }
00429 
00430               // Menu handlers
00431               private void menuExit_Click(object sender, System.EventArgs e)
00432               {
00433                      this.Close();
00434               }
00435 
00436               private void menuAbout_Click(object sender, System.EventArgs e)
00437               {
00438                      // TODO about message box
00439                      MessageBox.Show(this, "CSBrowse Test Application", "CSBrowse");
00440               }
00441 
00442 
00443        }
00444 }