十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
用msgbox()显示对话框
创新互联公司专注于企业成都营销网站建设、网站重做改版、乌当网站定制设计、自适应品牌网站建设、H5技术、商城网站定制开发、集团公司官网建设、外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为乌当等各大城市提供网站开发制作服务。
msgbox的用法很多,基础的就是msgbox(“你要显示的内容”)
或者msgbox(“你要显示的内容”,16,"对话框名称")'16是对话框的类型,还有几个键的组合代码,这个你可以
查查
,很多,或者你也可以用提示给出的类型,比如MsgBoxStyle.Exclamation就是显示错误对话框,
读文件内容到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就好
Filter 属性设置当前文件名筛选字符串,该字符串确定出现在对话框的“文件类型”框中的选项。
openFileDialog1.InitialDirectory = "c:\\" ;
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
openFileDialog1.FilterIndex = 1 ; // 获取或设置文件对话框中当前选定筛选器的索引;
openFileDialog1.RestoreDirectory = true ;
对于每个筛选选项,筛选器字符串都包含筛选器说明,后接一垂直线条 (|) 和筛选器模式。不同筛选选项的字符串由垂直线条隔开。
可以利用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