MessageBox: 预定义对话框类,用于向用户显示信息
'MessageBox.Show(Message, Caption, Buttons, Icon) 预定义对话框类,用于想用户显示信息
Dim Result As DialogResult
Result = MessageBox.Show("确定要删除吗", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) '返回的是DialogResult型的枚举值,用于拍段用户单击了那个按钮
If Result = DialogResult.OK Then
MessageBox.Show("单击了[是]按钮", "提示")
Else If Result = DialogResult.No Then
MessageBox.Show("单击了[否]按钮", "提示")
Else
MessageBox.Show("单击了[取消]按钮", "提示")
End If
打开文件OpenFileDialog对话框
Dim dlg As New OpenFileDialog '打开文件对话框对象
dlg.Filter = "文本文件|*.txt|图形文件|*.bmp;*.jpg;*.gif" '过滤器,用|分割
dlg.Multiselect = True '允许选择多个文件
If dlg.ShowDialog = DialogResult.OK Then
MessageBox.Show("你选择了" & dlg.FileNames.Length & "个文件,分别是:" & vbcrlf) 'FileNames字符数组,返回选定的多个文件,含路径
For Each FileName As String In dlg.FileNames '遍历字符数组,输出每个s文件名
MessageBox.Show(FileName, "提示")
Next
End If
保存文件对话框
Dim dlg As New SaveFileDialog
dlg.Filter = "文本文件|*.txt"
If dlg.ShowDialog = DialogResult.OK Then
MessageBox.Show("你要保存为:" & dlg.FileName, "提示")
End If
弹窗提示对话框PopMessage
'PopMessage(Message,Caption,Icon, Duration) '右下角弹窗,
PopMessage("此提示5秒钟后自动关闭!", "错误", PopIconEnum.Error, 5)
信息输入对话框: 两个函数InputValue,InputPassword
InputValue函数
Dim Val As Date = Date.Today
If InputValue(Val, "提示", "请输入日期:") = True Then
MessageBox.Show(Val)
End If
InputPassword函数
Dim Val As String
If InputPassword(Val, "提示", "请输入密码:") Then
MessageBox.Show(Val)
End If
用户信息
Output.Show("用户名:" & User.Name)
Output.Show("用户分组:" & User.Group)
Output.Show("用户角色:" & User.Roles)
Select Case User.Type
Case UserTypeEnum.Developer
Output.Show("用户级别:" & "开发者")
Case UserTypeEnum.Administrator
Output.Show("用户级别:" & "管理员")
Case UserTypeEnum.User
Output.Show("用户级别:" & "普通用户")
End Select
For Each us As UserInfo In Users
Output.Show("分组:" & us.Group)
Output.Show("名字:" & us.Name)
Next
Dim us1 As UserInfo = Users("开发者")
Output.Show("名字:" & us1.Name)
动态合成表达式
' 表达式中字符串用单引号,日期用#
Dim xm As String = "罗涛"
Dim rq As Date = #2/13/2001#
Dim sl As Integer = 1000
Dim flt As String = "姓名='{0}' And 日期 = #{1}# And 数量 > {2}"
flt = CExp(flt, xm, rq, sl)
Output.Show(flt)
执行外部程序Process
'Process执行外部程序
Dim Proc As New Process
'Proc.File = "C:\Users\nekofun\Desktop\test.xlsx"
'Proc.Verb = "Print" '指定打印动作
''Proc.Start() '开始执行
'For Each verb As String In Proc.Verbs '即将执行的文件支持动作的字符集合
' Output.Show(verb)
'Next
'Proc.File = "mailto:coder_luotao@163.com" '发送邮件
Proc.File = "www.baidu.com"
Proc.Start()
Proc.WaitForExit()
MessageBox.Show("打开完成!")
获取文件信息
Dim dlg As New OpenFileDialog
If dlg.ShowDialog = DialogResult.OK Then
Dim ifo As New FileInfo(dlg.FileName)
Output.Show("文件创建时间:" & ifo.CreationTime)
Output.Show("上次修改时间:" & ifo.LastWriteTime)
Output.Show("上次访问时间:" & ifo.LastAccessTime)
Output.Show("是否只读:" & ifo.ReadOnly)
Output.Show("是否隐藏:" & ifo.Hidden)
output.Show("文件路径:" & ifo.Path)
Output.Show("文件大小:" & ifo.Length)
Output.Show("文件名称:" & ifo.Name)
Output.Show("扩展名:" & ifo.Extension)
End If
文件与目录操作FileSys
Dim s As String = "I love Foxtable"
Dim fl As String = "C:\fox\test.txt" '准备存储内容的目标文件
If FileSys.DirectoryExists("C:\fox") = False Then '若目标目录不存在则创建该目录
FileSys.CreateDirectory("C:\fox")
End If
If FileSys.FileExists(fl) Then '若目标文件已存在则删除该文件
FileSys.DeleteFile(fl)
End If
FileSys.WriteAllText(fl, s, False) '覆盖内容
FileSys.WriteAllText(fl, vbcrlf & "我喜欢狐表", True) '追加内容
s = FileSys.ReadAllText(fl, Encoding.Default)
MessageBox.Show(s, "内容")
随机数随机字符
Dim v1, v2, v3 As Integer
v1 = Rand.Next() '随机整数
v2 = Rand.Next(100) '0到100的随机整数
v3 = Rand.Next(200, 300) '200到300的随机整数
For i As Integer = 0 To 9
Output.Show(Rand.NextDouble) '0到1间的小数10个
Next
Dim s As String = Rand.NextString(10) '10个随机字符
Output.Show(s)
朗读播放
'朗读
Dim sp As New DotNetSpeech.SpVoice()
sp.Speak("I am from China.", DotNetSpeech.SpeechVoiceSpeakFlags.SVSFlagsAsync)
'播放
Audio.Play("C:\music\test.wav")
系统变量
ApplicationTitle = "卷王"
Dim fl As String = ProjectPath & "test.txt"
Output.Show(fl)
Dim ip As String = FileSys.ReadAllText(fl, Encoding.Default)
MessageBox.Show(ip, "内容")
保存设置信息
- 函数方式 SaveConfigValue\GetConfigValue\RemoveConfigItem\ClearConfigItem
'设置用户使用项目最多使用10次(事件AfterOpenProject,打开项目后触发)
Dim n As Integer
n = GetConfigValue("Count", 1)
If n > 10 Then
MessageBox.Show("超出使用次数10")
Syscmd.Project.Exit() '退出Foxtable
Else
n = n + 1
SaveConfigValue("Count", n)
End If
- 注册表方式
SetValue: 向注册表写入值
GetValue: 向注册表读取值
Dim Count As Integer
Count = Registry.GetValue("HKEY_CURRENT_USER\Software\MyApp", "Count", 0)
Registry.SetValue("HKEY_CURRENT_USER\Software\MyApp", "Count", Count + 1)
Output.Show(Count)