⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.vb

📁 Visual Basic.net 实例入门
💻 VB
📖 第 1 页 / 共 2 页
字号:
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 8
        Me.Button1.Text = "附件(&A)..."
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(304, 312)
        Me.Button2.Name = "Button2"
        Me.Button2.TabIndex = 12
        Me.Button2.Text = "发送(&S)"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(16, 96)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(56, 16)
        Me.Label3.TabIndex = 0
        Me.Label3.Text = "标题:"
        '
        'OpenFileDialog1
        '
        Me.OpenFileDialog1.Filter = "所有文件 (*.*)|*.*"
        Me.OpenFileDialog1.InitialDirectory = "C:\"
        '
        'Panel1
        '
        Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.Panel1.Controls.AddRange(New System.Windows.Forms.Control() {Me.ComboBox1, Me.Label7, Me.Button1, Me.TextBox4, Me.Label5, Me.TextBox5, Me.Label6, Me.TextBox6, Me.TextBox1, Me.Label4, Me.Label1, Me.Label2, Me.Label3, Me.RichTextBox1, Me.TextBox2, Me.TextBox3, Me.Format1, Me.Format2})
        Me.Panel1.Location = New System.Drawing.Point(8, 8)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(464, 296)
        Me.Panel1.TabIndex = 10
        '
        'Label6
        '
        Me.Label6.Location = New System.Drawing.Point(16, 48)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(56, 16)
        Me.Label6.TabIndex = 0
        Me.Label6.Text = "抄送:"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(16, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(56, 16)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "收件人:"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(232, 24)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(56, 16)
        Me.Label2.TabIndex = 0
        Me.Label2.Text = "发送人:"
        '
        'RichTextBox1
        '
        Me.RichTextBox1.Location = New System.Drawing.Point(80, 120)
        Me.RichTextBox1.Name = "RichTextBox1"
        Me.RichTextBox1.Size = New System.Drawing.Size(368, 96)
        Me.RichTextBox1.TabIndex = 7
        Me.RichTextBox1.Text = ""
        '
        'Button4
        '
        Me.Button4.Location = New System.Drawing.Point(224, 312)
        Me.Button4.Name = "Button4"
        Me.Button4.TabIndex = 14
        Me.Button4.Text = "重写(&R)"
        '
        'Button3
        '
        Me.Button3.Location = New System.Drawing.Point(384, 312)
        Me.Button3.Name = "Button3"
        Me.Button3.TabIndex = 13
        Me.Button3.Text = "退出(&X)"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(480, 345)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button4, Me.Panel1, Me.Button3, Me.Button2})
        Me.MaximizeBox = False
        Me.Menu = Me.MainMenu1
        Me.MinimizeBox = False
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Email传送"
        Me.Panel1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
        TextBox4.Text = OpenFileDialog1.FileName
        '在TextBox4中显示出用户选择的附件文件名
    End Sub

    Private Sub OpenFile()
        OpenFileDialog1.ShowDialog()
        '打开“打开文件”对话框
    End Sub

    Private Sub SendMail()
        If TextBox1.Text = "" Then
            MessageBox.Show("必须输入收件人的地址。", "Email错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            '判断收件人一栏是否为空
        End If

        If TextBox3.Text = "" Then
            MessageBox.Show("必须输入邮件的标题。", "Email错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            '判断邮件标题一栏是否为空
        End If

        If RichTextBox1.Text = "" Then
            MessageBox.Show("必须输入邮件的内容。", "Email错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            '判断邮件内容一栏是否为空
        End If

        If TextBox1.Text <> "" And TextBox2.Text <> "" And RichTextBox1.Text <> "" Then
            Dim mail As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage()
            '定义新邮件

            Select Case ComboBox1.Text
                Case "高"
                    mail.Priority = Web.Mail.MailPriority.High
                    '设置邮件的优先级为“高”

                Case "中", ""
                    mail.Priority = Web.Mail.MailPriority.Normal
                    '设置邮件的优先级为“中”

                Case "低"
                    mail.Priority = Web.Mail.MailPriority.Low
                    '设置邮件的优先级为“低”

            End Select

            mail.To = TextBox1.Text
            '设置邮件的收信人属性
            mail.From = TextBox2.Text
            '设置邮件的发信人属性
            mail.Subject = TextBox3.Text
            '设置邮件的主题
            If TextBox5.Text <> "" Then
                mail.Cc = TextBox5.Text
                '设置邮件的抄送属性
            End If
            If TextBox6.Text <> "" Then
                mail.Bcc = TextBox6.Text
                '设置邮件的密送属性
            End If

            If Format1.Checked = True Then
                mail.BodyFormat = System.Web.Mail.MailFormat.Text
            Else
                mail.BodyFormat = System.Web.Mail.MailFormat.Html
            End If
            '设置邮件格式
            If TextBox4.Text <> "" Then
                mail.Attachments.Add(New System.Web.Mail.MailAttachment(TextBox4.Text))
            End If
            '设置附件
            mail.Body = RichTextBox1.Text
            '设置邮件内容

            Try
                System.Web.Mail.SmtpMail.Send(mail)
                '发送邮件
            Catch err As Exception
                '捕获并忽略异常
            End Try

            MessageBox.Show("邮件已经成功发送。", "发送", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            '向用户发出提示信息
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        SendMail()
        '调用发送邮件函数
    End Sub

    Private Sub mSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mSend.Click
        SendMail()
        '调用发送邮件函数
    End Sub

    Private Sub mAccessories_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mAccessories.Click
        OpenFile()
        '调用打开文件函数
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        OpenFile()
        '调用打开文件函数
    End Sub

    Private Sub mTxt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mTxt.Click
        Format1.Checked = True
        '修改相应的Format1的Checked属性
    End Sub

    Private Sub mHTML_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mHTML.Click
        Format2.Checked = True
        '修改相应的Format2的Checked属性
    End Sub

    Private Sub ExitForm()
        Application.Exit()
        '退出应用程序
    End Sub

    Private Sub mExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mExit.Click
        ExitForm()
        '调用退出函数
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        ExitForm()
        '调用退出函数
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Reset()
        '调用初始化函数

        ComboBox1.Items.Add("高")
        ComboBox1.Items.Add("中")
        ComboBox1.Items.Add("低")
        ComboBox1.Text = "中"
        '初始化ComboBox1的各属性

        OpenFileDialog1.Filter = "所有文件(*.*)|*.*"
        '初始化OpenFileDialog1的Filter属性
    End Sub

    Private Sub Reset()
        TextBox1.Clear()
        TextBox2.Clear()
        TextBox3.Clear()
        TextBox4.Clear()
        TextBox5.Clear()
        TextBox6.Clear()
        RichTextBox1.Clear()
        ComboBox1.Text = "中"
        Format1.Checked = True
        TextBox1.Focus()
        '对各控件进行初始化
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Reset()
        '调用初始化函数
    End Sub

    Private Sub mReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mReset.Click
        Reset()
        '调用初始化函数
    End Sub

    Private Sub mAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mAbout.Click
        Dim fAbout As New formAbout()
        fAbout.Show()
        '“关于”窗口
    End Sub
End Class

⌨️ 快捷键说明

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