VB.Net/Application/Web Browser

Материал из VB Эксперт
Перейти к: навигация, поиск

A Basic Web Browser

<source lang="vbnet"> Imports System.IO Imports System.Net Imports System.Text Imports System.Windows.Forms

public class MainClass

  Shared Sub Main()
      Dim form1 As Form = New Form1
      Application.Run(form1)
  End Sub

End Class

Public Class Form1

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       buttonBack.Enabled = False
       buttonForward.Enabled = False
       buttonStop.Enabled = False
   End Sub
   Private Sub buttonBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonBack.Click
       WebBrowser1.GoBack()
       TextBox1.Text = WebBrowser1.Url.ToString()
   End Sub
   Private Sub buttonForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonForward.Click
       WebBrowser1.GoForward()
       TextBox1.Text = WebBrowser1.Url.ToString()
   End Sub
   Private Sub buttonStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonStop.Click
       WebBrowser1.Stop()
   End Sub
   Private Sub buttonRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonRefresh.Click
       WebBrowser1.Refresh()
   End Sub
   Private Sub buttonHome_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonHome.Click
       WebBrowser1.GoHome()
       TextBox1.Text = WebBrowser1.Url.ToString()
   End Sub
   Private Sub buttonSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonSubmit.Click
       WebBrowser1.Navigate(TextBox1.Text)
   End Sub
   Private Sub WebBrowser1_CanGoBackChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles WebBrowser1.CanGoBackChanged
       If WebBrowser1.CanGoBack = True Then
           buttonBack.Enabled = True
       Else
           buttonBack.Enabled = False
       End If
   End Sub
   Private Sub WebBrowser1_CanGoForwardChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles WebBrowser1.CanGoForwardChanged
       If WebBrowser1.CanGoForward = True Then
           buttonForward.Enabled = True
       Else
           buttonForward.Enabled = False
       End If
   End Sub
   Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
       buttonStop.Enabled = False
   End Sub
   Private Sub WebBrowser1_Navigated(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles WebBrowser1.Navigated
       TextBox1.Text = WebBrowser1.Url.ToString()
       Me.Text = WebBrowser1.DocumentTitle.ToString()
   End Sub
   Private Sub WebBrowser1_Navigating(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
       buttonStop.Enabled = True
   End Sub

End Class

<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.buttonBack = New System.Windows.Forms.Button
       Me.buttonForward = New System.Windows.Forms.Button
       Me.buttonStop = New System.Windows.Forms.Button
       Me.buttonHome = New System.Windows.Forms.Button
       Me.buttonRefresh = New System.Windows.Forms.Button
       Me.TextBox1 = New System.Windows.Forms.TextBox
       Me.buttonSubmit = New System.Windows.Forms.Button
       Me.WebBrowser1 = New System.Windows.Forms.WebBrowser
       Me.SuspendLayout()
       "
       "buttonBack
       "
       Me.buttonBack.Location = New System.Drawing.Point(12, 12)
       Me.buttonBack.Name = "buttonBack"
       Me.buttonBack.Size = New System.Drawing.Size(75, 23)
       Me.buttonBack.TabIndex = 0
       Me.buttonBack.Text = "Back"
       Me.buttonBack.UseVisualStyleBackColor = True
       "
       "buttonForward
       "
       Me.buttonForward.Location = New System.Drawing.Point(93, 12)
       Me.buttonForward.Name = "buttonForward"
       Me.buttonForward.Size = New System.Drawing.Size(75, 23)
       Me.buttonForward.TabIndex = 1
       Me.buttonForward.Text = "Forward"
       Me.buttonForward.UseVisualStyleBackColor = True
       "
       "buttonStop
       "
       Me.buttonStop.Location = New System.Drawing.Point(174, 12)
       Me.buttonStop.Name = "buttonStop"
       Me.buttonStop.Size = New System.Drawing.Size(75, 23)
       Me.buttonStop.TabIndex = 2
       Me.buttonStop.Text = "Stop"
       Me.buttonStop.UseVisualStyleBackColor = True
       "
       "buttonHome
       "
       Me.buttonHome.Location = New System.Drawing.Point(255, 12)
       Me.buttonHome.Name = "buttonHome"
       Me.buttonHome.Size = New System.Drawing.Size(75, 23)
       Me.buttonHome.TabIndex = 3
       Me.buttonHome.Text = "Home"
       Me.buttonHome.UseVisualStyleBackColor = True
       "
       "buttonRefresh
       "
       Me.buttonRefresh.Location = New System.Drawing.Point(336, 12)
       Me.buttonRefresh.Name = "buttonRefresh"
       Me.buttonRefresh.Size = New System.Drawing.Size(75, 23)
       Me.buttonRefresh.TabIndex = 4
       Me.buttonRefresh.Text = "Refresh"
       Me.buttonRefresh.UseVisualStyleBackColor = True
       "
       "TextBox1
       "
       Me.TextBox1.Location = New System.Drawing.Point(12, 41)
       Me.TextBox1.Name = "TextBox1"
       Me.TextBox1.Size = New System.Drawing.Size(399, 20)
       Me.TextBox1.TabIndex = 5
       "
       "buttonSubmit
       "
       Me.buttonSubmit.Location = New System.Drawing.Point(417, 12)
       Me.buttonSubmit.Name = "buttonSubmit"
       Me.buttonSubmit.Size = New System.Drawing.Size(75, 49)
       Me.buttonSubmit.TabIndex = 6
       Me.buttonSubmit.Text = "Submit"
       Me.buttonSubmit.UseVisualStyleBackColor = True
       "
       "WebBrowser1
       "
       Me.WebBrowser1.Location = New System.Drawing.Point(12, 67)
       Me.WebBrowser1.MinimumSize = New System.Drawing.Size(20, 20)
       Me.WebBrowser1.Name = "WebBrowser1"
       Me.WebBrowser1.Size = New System.Drawing.Size(655, 427)
       Me.WebBrowser1.TabIndex = 7
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(679, 506)
       Me.Controls.Add(Me.WebBrowser1)
       Me.Controls.Add(Me.buttonSubmit)
       Me.Controls.Add(Me.TextBox1)
       Me.Controls.Add(Me.buttonRefresh)
       Me.Controls.Add(Me.buttonHome)
       Me.Controls.Add(Me.buttonStop)
       Me.Controls.Add(Me.buttonForward)
       Me.Controls.Add(Me.buttonBack)
       Me.Name = "Form1"
       Me.Text = "Form1"
       Me.ResumeLayout(False)
       Me.PerformLayout()
   End Sub
   Friend WithEvents buttonBack As System.Windows.Forms.Button
   Friend WithEvents buttonForward As System.Windows.Forms.Button
   Friend WithEvents buttonStop As System.Windows.Forms.Button
   Friend WithEvents buttonHome As System.Windows.Forms.Button
   Friend WithEvents buttonRefresh As System.Windows.Forms.Button
   Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
   Friend WithEvents buttonSubmit As System.Windows.Forms.Button
   Friend WithEvents WebBrowser1 As System.Windows.Forms.WebBrowser

End Class

      </source>