0

单击按钮时,我需要显示两个图像。首先,用户将浏览这两个图像,单击第三个按钮后,它应该显示这两个图像。到目前为止我有这个代码。我是vb的新手

 Dim dialog As New OpenFileDialog()
    If DialogResult.OK = dialog.ShowDialog Then
        TextBox2.Text = dialog.FileName
    End If
4

1 回答 1

1

在此处输入图像描述

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim fdialog As New OpenFileDialog()
    fdialog.FileName = String.Empty
    fdialog.Multiselect = True

    If fdialog.ShowDialog = DialogResult.OK Then
        If fdialog.FileNames.Length = 2 Then
            PictureBox1.Image = System.Drawing.Image.FromFile(fdialog.FileNames(0))
            TextBox1.Text = fdialog.FileNames(0)
            PictureBox2.Image = System.Drawing.Image.FromFile(fdialog.FileNames(1))
            TextBox2.Text = fdialog.FileNames(1)
        ElseIf fdialog.FileNames.Length = 1 Then
            PictureBox1.Image = System.Drawing.Image.FromFile(fdialog.FileName)
            TextBox1.Text = fdialog.FileName
            PictureBox2.Image = Nothing
            TextBox2.Text = String.Empty
        End If
    End If
End Sub

以下代码进入“加载”按钮的单击事件。
问候 ...

于 2012-05-07T14:50:56.087 回答