以前,我使用此代码仅将图像添加到应用程序(GIF不起作用):
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles BtnImgBrowse.Click
Dim t As New OpenFileDialog
t.Filter = "*.JPG;*.PNG;*.GIF|*.JPG;*.PNG;*.GIF"
If t.ShowDialog = DialogResult.OK Then
TxtImgFile.Text = t.FileName
Clipboard.SetImage(Image.FromFile(TxtImgFile.Text))
End If
End Sub
现在,我也想添加PDfs,文档和Excel文件,因此我对代码进行了一些更改,但似乎不起作用:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles BtnImgBrowse.Click
Dim t As New OpenFileDialog
t.Filter = "*.JPG;*.PNG;*.GIF;*.DOC;*.DOCX;*.XLS;*.XLSX;*.PDF|*.JPG;*.PNG;*.GIF;*.DOC;*.DOCX;*.XLS;*.XLSX;*.PDF"
If t.ShowDialog = DialogResult.OK Then
TxtImgFile.Text = t.FileName
Clipboard.ContainsData(TxtImgFile.Text)
End If
End Sub
它只是从我的系统中复制数据。不是我在应用程序中选择的文件。