form1.frm

来自「VB源码,是初学者的福因.让你很快掌握VB编程」· FRM 代码 · 共 105 行

FRM
105
字号
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "mswinsck.ocx"
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   3540
   ClientLeft      =   2790
   ClientTop       =   2190
   ClientWidth     =   6630
   LinkTopic       =   "Form1"
   ScaleHeight     =   3540
   ScaleWidth      =   6630
   Begin VB.TextBox txtWebPage 
      Height          =   2655
      Left            =   120
      MultiLine       =   -1  'True
      ScrollBars      =   3  'Both
      TabIndex        =   5
      Top             =   720
      Width           =   6375
   End
   Begin VB.TextBox txtLocation 
      Height          =   375
      Left            =   2760
      TabIndex        =   3
      Text            =   "/right.html"
      Top             =   240
      Width           =   3015
   End
   Begin VB.TextBox txtWebServer 
      Height          =   375
      Left            =   120
      TabIndex        =   1
      Text            =   "LocalHost"
      Top             =   240
      Width           =   2055
   End
   Begin VB.CommandButton cmdconnect 
      Caption         =   "连接"
      Height          =   375
      Left            =   5880
      TabIndex        =   0
      Top             =   240
      Width           =   615
   End
   Begin MSWinsockLib.Winsock Winsock1 
      Left            =   2280
      Top             =   120
      _ExtentX        =   741
      _ExtentY        =   741
   End
   Begin VB.Label Label2 
      Caption         =   "文件名称"
      Height          =   255
      Left            =   3000
      TabIndex        =   4
      Top             =   0
      Width           =   1935
   End
   Begin VB.Label Label1 
      Caption         =   "Web服务器"
      Height          =   255
      Left            =   120
      TabIndex        =   2
      Top             =   0
      Width           =   1815
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub cmdconnect_Click()
    On Error Resume Next
    Text1.Height = Height - 500
    Text1.Width = Width - 500
    Winsock1.Close
    Winsock1.RemoteHost = txtWebServer.Text
    Winsock1.RemotePort = 80
    Winsock1.Connect
End Sub


Private Sub Winsock1_Connect()
    On Error Resume Next
    Dim strCommand As String
    Dim strWebPage As String
  
    strWebPage = txtLocation.Text
    strCommand = "GET " + strWebPage + " HTTP/1.0" + vbCrLf
    strCommand = strCommand + "Accept: */*" + vbCrLf
    strCommand = strCommand + "Accept: text/html" + vbCrLf
    strCommand = strCommand + vbCrLf
    Winsock1.SendData strCommand
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    On Error Resume Next
    Dim webData As String
  
    Winsock1.GetData webData, vbString
    txtWebPage.Text = txtWebPage.Text + webData
End Sub

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?