简体   繁体   English

如何在VB.NET中创建一个按钮以允许用户选择文件?

[英]How do I make a Button in VB.NET Allow a User to Select a File?

I am making a Crypter in Visual Basic Express Edition 2010, and I am experiencing some problems. 我在Visual Basic Express Edition 2010中制作了密码,并且遇到了一些问题。 I am trying to make it so the user clicks on a button in the GUI, and it allows them to pick a file to Crypt. 我正在尝试使用户单击GUI中的按钮,并允许他们选择要发送到Crypt的文件。 Does anyone have any ideas on how to do that? 有没有人对如何做有任何想法? Here is the code I originally used to make it, but it is not working :( All help is appreciated! 这是我最初用来制作的代码,但是它不起作用:(感谢所有帮助!

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
    With OpenFileDialog1
        .FileName = ""
        .Filter = "Executables (*.exe)|*.exe|All files (*.*)|*.*"
        .Title = "The Justice Crypter"
        .ShowDialog()
        TextBox1.Text = .FileName
        infectedfile = TextBox1.Text
    End With
End Sub

Thanks guys. 多谢你们。

The OpenFileDialog is a WPF wrapper of the Win32 Control this works for me. OpenFileDialog是Win32控件的WPF包装,对我有用。

Class MainWindow 
    Dim WithEvents openFileDialog1 As New Microsoft.Win32.OpenFileDialog
    Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
        With OpenFileDialog1
            .FileName = ""
            .Filter = "Executables (*.exe)|*.exe|All files (*.*)|*.*"
            .Title = "The Justice Crypter"
            .ShowDialog()
            TextBox1.Text = .FileName
            'infectedfile = TextBox1.Text
        End With
    End Sub
End Class

OpenFileDialog1 is null. OpenFileDialog1为空。
You need to initialize it to a New OpenFileDialog() . 您需要将其初始化为New OpenFileDialog()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM