vb.net打开对话 vb 打开文件对话框
vb.net使用打开对话框,打开一个文本文件显示在文本框中,然后对文本框中的信息进行编辑后
读文件内容到TextBox :
成都创新互联专注于通城网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供通城营销型网站建设,通城网站制作、通城网页设计、通城网站官网定制、成都小程序开发服务,打造通城网络公司原创品牌,更为您提供通城网站排名全网营销落地服务。
Try
Using sr As StreamReader = New StreamReader("C:\\TestFile.txt")
textbox1.Text = sr.ReadToEnd()
End Using
Catch E As Exception
Console.WriteLine(E.Message)
End Try
修改完成后,保存到文件:
Using sw As StreamWriter = New StreamWriter("C:\\TestFile.txt")
sw.Write(textbox1.Text)
sw.Close()
End Using
其中,流构造的参数
New StreamReader("C:\\TestFile.txt")
New StreamWriter("C:\\TestFile.txt")
中的"C:\\TestFile.txt"可以用OpenFileDialog和SaveFileDialog的FileName属性替换.
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.InitialDirectory = "c:\"
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
openFileDialog1.FilterIndex = 2
openFileDialog1.RestoreDirectory = True
If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Try
Using sr As StreamReader = New StreamReader(openFileDialog1.FileName)
textbox1.Text = sr.ReadToEnd()
End Using
Catch E As Exception
Console.WriteLine(E.Message)
End Try
End If
保存的时候换成SaveFileDialog就好
VB.net怎么弹出如下类似的对话框(看图)?
可以利用msgbox 实现,也可以通过另外的窗体上画出表格实现
方法一,利用msgbox:
Private Sub Command1_Click()Dim a As Long, b As Long, c As LongMsgBox "┌────┬────┬────┐" vbCrLf _ "│ 库存1 │ 库存2 │ 库存3 │" vbCrLf _ "├────┼────┼────┤" vbCrLf _ "│" formatstr(a) "│" formatstr(b) "│" formatstr(c) "│" vbCrLf _ "└────┴────┴────┘" End SubPrivate Function formatstr(ByVal inputStr As String) As StringDim j As Integerj = (8 - Len(inputStr)) \ 2formatstr = Space(j) inputStr Space(j) Space((8 - Len(inputStr)) Mod 2)End Function
方法二,利用窗体实现:
’新建form2窗体‘将以下代码复制到form2窗体中Private Sub Form_Load()ShowPrint "┌────┬────┬────┐" vbCrLf _ "│ 库存1 │ 库存2 │ 库存3 │" vbCrLf _ "├────┼────┼────┤" vbCrLf _ "│" formatstr(a) "│" formatstr(b) "│" formatstr(c) "│" vbCrLf _ "└────┴────┴────┘" End SubPrivate Function formatstr(ByVal inputStr As String) As StringDim j As Integerj = (8 - Len(inputStr)) \ 2formatstr = Space(j) inputStr Space(j) Space((8 - Len(inputStr)) Mod 2)End Function‘将以下代码复制在form1窗体中Private Sub Command1_Click()Form2.ShowEnd Sub
VB.NET中,文件对话框(OpenFileDialog)显示某种设定的文件类型需要修改什么属性?
Filter 属性设置当前文件名筛选字符串,该字符串确定出现在对话框的“文件类型”框中的选项。
openFileDialog1.InitialDirectory = "c:\\" ;
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
openFileDialog1.FilterIndex = 1 ; // 获取或设置文件对话框中当前选定筛选器的索引;
openFileDialog1.RestoreDirectory = true ;
对于每个筛选选项,筛选器字符串都包含筛选器说明,后接一垂直线条 (|) 和筛选器模式。不同筛选选项的字符串由垂直线条隔开。
VB.net如何打开对话框获取文件名?注意不是完整路径还有没有后缀名!
Dim dialog As OpenFileDialog = New OpenFileDialog
If dialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim filename As String
filename = dialog.FileName
Dim results() As String
results = filename.Split("\")
filename = results(results.Length - 1)
filename = filename.Substring(0, filename.LastIndexOf("."))
MessageBox.Show(filename)
End If
dialog.Dispose()
vb.net中用什么方法显示对话框?
用msgbox()显示对话框
msgbox的用法很多,基础的就是msgbox(“你要显示的内容”)
或者msgbox(“你要显示的内容”,16,"对话框名称")'16是对话框的类型,还有几个键的组合代码,这个你可以
查查
,很多,或者你也可以用提示给出的类型,比如MsgBoxStyle.Exclamation就是显示错误对话框,
VB.net 对话框
你这2个按钮的目的不是一样吗
Dim fbd As New FolderBrowserDialogfbd.Description = "请选择文件夹。"fbd.RootFolder = Environment.SpecialFolder.Desktop '根目录
fbd.SelectedPath = "C:\Windows" '默认打开文件夹
fbd.ShowNewFolderButton = True '是否可以创建新文件夹
If fbd.ShowDialog(Me) = DialogResult.OK Then
textbox1.text=fbd.SelectedPath
End If
网页标题:vb.net打开对话 vb 打开文件对话框
标题来源:http://myzitong.com/article/hgdogg.html