❶ 求VB.NET获取文件路径的方法
Private Sub Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Browse.Click
If (OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK) Then
FileName = OpenFileDialog1.FileName
TextBox1.Text = FileName
End If
End Sub
用来openfiledialog控件,在你要选择文件自的botton的click事件下面下选择文件的代码,把文件的路径显示到textbox1.text里面
❷ VB.net窗体设计中,如何读取.txt文件中的数据
1、新建一个标准的VB EXE工程,只有一个Form,Form上有两个按钮:Command1和Command2。
2、双击Command1添加如下代码
Private Sub Command1_Click()
Dim strFile As String
Dim intFile As Integer
Dim strData As String
strFile = "c:\学生成绩.txt"
intFile = FreeFile
Open strFile For Input As intFile
strData = StrConv(InputB(FileLen(strFile), intFile), vbUnicode)
Debug.Print strData
Close intFile
End Sub
3、按F8开始单步调试代码,点击Command1,进入单步调试功能,
4、多次按下F8或直接按下F5运行完成,就完成了读取文本文件内容并输出到立即窗口。
❸ vb.net中,如何点击按钮调出选择文件窗口选中图片并在picturebox中显示出来
button , OpenFileDialog , PictureBox , textbox 控件,我把图片显示在 picturebox 中,而路
径存放在 textbox 中,不知道这样行不行。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim filename As String
OpenFileDialog1.Filter = "jpg files (*.jpg)|*.jpg"
OpenFileDialog1.FilterIndex = 1
If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
filename = OpenFileDialog1.FileName
Else
End
End If
If Not (PictureBox1.Image Is Nothing) Then
PictureBox1.Image.Dispose()
PictureBox1.Image = Nothing
End If
'PictureBox1.Image = System.Drawing.Image.FromFile(filename)
去掉注释后就显示图片
TextBox1.Text = filename
End Sub
picturebox中只记录文件存放的路径,我找了一个 ImageLocation 函数
PictureBox1.ImageLocation = filename 不过还是会显示图片