单击按钮时显示图像

时间:2012-05-06 14:09:45

标签: vb.net winforms

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

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

1 个答案:

答案 0 :(得分:1)

enter image description here

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

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