vb.net对话框操作实例(一)

 时间:2026-02-14 09:06:34

1、Private Sub btn2Buttons_Click(sender As Object,

e As EventArgs) Handles btn2Buttons.Click

If MessageBox.Show("Your Internet connection will now be closed.",

   "Network Notification", MessageBoxButtons.OKCancel,

   MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) _

   = Windows.Forms.DialogResult.OK Then

   lblResults.Text = "OK Clicked"

   'Call some method here

Else

   lblResults.Text = "Cancel Clicked"

   'Call some method here

End If

End Sub

vb.net对话框操作实例(一)

2、Private Sub btn3Buttons_Click(sender As Object,

    e As EventArgs) Handles btn3Buttons.Click

    'Declare local variable

    Dim intResult As DialogResult

    'Get the results of the button clicked

    intResult =

   MessageBox.Show("Do you want to save changes to New Document?",

        "My Word Processor", MessageBoxButtons.YesNoCancel,

        MessageBoxIcon.Warning, MessageBoxDefaultButton.Button3)

    'Process the results of the button clicked

    Select Case intResult

        Case Windows.Forms.DialogResult.Yes

            lblResults.Text = "Yes Clicked"

            'Do yes processing here

        Case Windows.Forms.DialogResult.No

            lblResults.Text = "No Clicked"

            'Do no processing here

        Case Windows.Forms.DialogResult.Cancel

            lblResults.Text = "Cancel Clicked"

            'Do cancel processing here

    End Select

End Sub

vb.net对话框操作实例(一)

1、Public Class Dialogs

    'Declare variable

    Private strFileName As String

Private Sub btnOpen_Click(sender As Object,

    e As EventArgs) Handles btnOpen.Click

    'Set the Open dialog properties

        OpenFileDialog1.Filter = "Text Documents

          (*.txt)|*.txt|All Files (*.*)|*.*"

        OpenFileDialog1.FilterIndex = 1

        OpenFileDialog1.Title = "Demo Open File Dialog"

    'Show the Open dialog if the user clicks the Open button,

    'load the file

    If OpenFileDialog1.ShowDialog =

       Windows.Forms.DialogResult.OK Then

       Try

         'Save the file path and name

         strFileName = OpenFileDialog1.FileName

       Catch ex As Exception

         MessageBox.Show(ex.Message,

            My.Application.Info.Title,

            MessageBoxButtons.OK, MessageBoxIcon.Error)

       End Try

    End If

End Sub

vb.net对话框操作实例(一)

2、Try

    'Save the file path and name

    strFileName = OpenFileDialog1.FileName

    Dim fileContents As String

    fileContents =

       My.Computer.FileSystem.ReadAllText(strFileName)

    'Display the file contents in the text box

    txtFile.Text = fileContents

Catch ex As Exception

vb.net对话框操作实例(一)

  • unity 如何实时获取麦克风的音量
  • 孤岛惊魂6DLC什么时候上线
  • CST微波工作室仿真怎样选择求解器
  • 剑灵散播和阻止谣言的人任务怎么做?
  • Edge浏览器如何删除全部网站的Cookie及数据?
  • 热门搜索
    如何教孩子加减法 新股怎么申购简单流程 慈溪旅游团 剑灵数据图怎么导入 如何拒绝别人的表白 海地在哪里 如何推广平台 孕妇怕冷是怎么回事 幼儿挑食怎么办 qq九仙图标怎么点亮