-1

好的,所以基本上我有一个标签,我希望用户能够向它添加一个文件位置,以便进一步访问。像..他选择文件A绑定到Label1。所以当他点击Label1时,文件A会打开..有什么建议吗?

4

2 回答 2

0

You could save the user specified file location to My.Settings as a string. Then you can open the file in the on click event of the label with something like System.Diagnostics.Process.Start(My.Settings.Label1Path)

于 2013-06-27T18:48:11.683 回答
0

在这里,您有一个执行所需操作的代码:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim fd As OpenFileDialog = New OpenFileDialog()
    Dim strFileName As String

    fd.InitialDirectory = "C:\"

    If fd.ShowDialog() = DialogResult.OK Then
        LinkLabel1.Text = System.IO.Path.GetFileName(fd.FileName)
    End If
End Sub

Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
    Process.Start(LinkLabel1.Text)
End Sub

您必须在表单中添加一个按钮 ( Button1) 和一个链接标签 ( LinkLabel1) 并使用此代码。

于 2013-06-27T18:43:59.493 回答