-
vb.net教程之程序对话框
程序对话框(相关vb.net教程)
有关对话框的一组控件:
打开文件对话框openfiledialog:
保存文件对话框savefiledialog:
颜色对话框colordialog:
字体对话框fontdialog:
常用属性:
Name:控件名。
Filename:对话框中所选择的文件名
Filenames:允许选择多个文件时,所选择的文件名数组。当multiselect为真时才可用。
Multiselect:弹出的选择文件对话框中,允许不允许选择多个。
Filter:显示的文件类型,它由“说明|*.类型”构成,一般放在窗体的load事件中。
DefaultExt:保存文件时默认扩展名,字符串,一般放在窗体的load事件中。
Color:对话框选定的颜色。
Font: 对话框选定的字体。
常用方法:
Showdialog:用以弹出对话框。
应用实例:制作一个图片浏览器
见,图片浏览器1
程序为:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ss As String
Op.ShowDialog()
ss = Op.FileName
PictureBox1.Image = Image.FromFile(ss)
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Op.Filter = "*.jpg|*.jpg|*.bmp|*.bmp"
End Sub
应用实例:制作一个可同时打开多个文件的图片浏览器,并能进行上下翻阅浏览。
见,可上下翻阅的图片浏览器,程序为:
Public Class Form1
Dim i As Integer
Dim j As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OpenF.Filter = "jpg file|*.jpg|bmp file|*.bmp|gif file|*.gif"
'OpenF.DefaultExt = "bmp"
OpenF.Multiselect = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenF.ShowDialog()
PictureBox1.Image = Image.FromFile(OpenF.FileName)
i = UBound(OpenF.FileNames)
MsgBox("选择的文件数为:" & Str(i + 1), 32, "提示")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
j = j + 1
If j >= i Then
j = i
Button2.Enabled = False
Button3.Enabled = True
End If
PictureBox1.Image = Image.FromFile(OpenF.FileNames(j))
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
j = j - 1
If j <= 0 Then
j = 0
Button3.Enabled = False
Button2.Enabled = True
End If
PictureBox1.Image = Image.FromFile(OpenF.FileNames(j))
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
End
End Sub
End Class
应用实例:通过颜色,字体对话框设置文本框中的字体,字号,字的颜色。
见,通用对话框综合实例[实验报告33 ]
程序为:
Public Class Form1
Dim ss As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
o.ShowDialog()
ss = o.FileName
P.Image = Image.FromFile(ss)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
C.ShowDialog()
L.ForeColor = C.Color
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
F.ShowDialog()
L.Font = F.Font
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
End
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
S.ShowDialog()
ss = S.FileName
ss = MsgBox("如果要真正的保存一个文件," & Chr(13) & Chr(13) & "还需要文件操作控件", 16, "注意!")
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
S.Filter = ("文本文件(*.txt)|*.txt")
S.DefaultExt = "txt"
o.Filter = ("图形文件*.jpg|*.jpg|*.bmp|*.bmp")
o.DefaultExt = "jpg"
End Sub
End Class
练习:试开发一个记事本软件。
见,小小记事本,程序为:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ColorDialog1.ShowDialog()
TextBox1.ForeColor = ColorDialog1.Color
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
FontDialog1.ShowDialog()
TextBox1.Font = FontDialog1.Font
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim n As Integer
Dim f As String
SaveFileDialog1.ShowDialog()
f = SaveFileDialog1.FileName
n = FreeFile()
FileOpen(n, f, OpenMode.Output)
Print(n, TextBox1.Text)
FileClose(n)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OpenFileDialog1.Filter = "文本文件|*.txt"
SaveFileDialog1.Filter = "文本文件|*.txt"
OpenFileDialog1.DefaultExt = "txt"
SaveFileDialog1.DefaultExt = "txt"
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim fn As Integer
Dim s As String = ""
OpenFileDialog1.FileName = ""
If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
fn = FreeFile()
FileOpen(fn, OpenFileDialog1.FileName, OpenMode.Input)
Do While Not EOF(fn)
s = s + LineInput(fn) + vbCrLf
Loop
FileClose(fn)
TextBox1.Text = s
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
End
End Sub
有关对话框的一组控件:
打开文件对话框openfiledialog:
保存文件对话框savefiledialog:
颜色对话框colordialog:
字体对话框fontdialog:
常用属性:
Name:控件名。
Filename:对话框中所选择的文件名
Filenames:允许选择多个文件时,所选择的文件名数组。当multiselect为真时才可用。
Multiselect:弹出的选择文件对话框中,允许不允许选择多个。
Filter:显示的文件类型,它由“说明|*.类型”构成,一般放在窗体的load事件中。
DefaultExt:保存文件时默认扩展名,字符串,一般放在窗体的load事件中。
Color:对话框选定的颜色。
Font: 对话框选定的字体。
常用方法:
Showdialog:用以弹出对话框。
应用实例:制作一个图片浏览器
见,图片浏览器1
程序为:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ss As String
Op.ShowDialog()
ss = Op.FileName
PictureBox1.Image = Image.FromFile(ss)
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Op.Filter = "*.jpg|*.jpg|*.bmp|*.bmp"
End Sub
应用实例:制作一个可同时打开多个文件的图片浏览器,并能进行上下翻阅浏览。
见,可上下翻阅的图片浏览器,程序为:
Public Class Form1
Dim i As Integer
Dim j As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OpenF.Filter = "jpg file|*.jpg|bmp file|*.bmp|gif file|*.gif"
'OpenF.DefaultExt = "bmp"
OpenF.Multiselect = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenF.ShowDialog()
PictureBox1.Image = Image.FromFile(OpenF.FileName)
i = UBound(OpenF.FileNames)
MsgBox("选择的文件数为:" & Str(i + 1), 32, "提示")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
j = j + 1
If j >= i Then
j = i
Button2.Enabled = False
Button3.Enabled = True
End If
PictureBox1.Image = Image.FromFile(OpenF.FileNames(j))
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
j = j - 1
If j <= 0 Then
j = 0
Button3.Enabled = False
Button2.Enabled = True
End If
PictureBox1.Image = Image.FromFile(OpenF.FileNames(j))
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
End
End Sub
End Class
应用实例:通过颜色,字体对话框设置文本框中的字体,字号,字的颜色。
见,通用对话框综合实例[实验报告33 ]
程序为:
Public Class Form1
Dim ss As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
o.ShowDialog()
ss = o.FileName
P.Image = Image.FromFile(ss)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
C.ShowDialog()
L.ForeColor = C.Color
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
F.ShowDialog()
L.Font = F.Font
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
End
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
S.ShowDialog()
ss = S.FileName
ss = MsgBox("如果要真正的保存一个文件," & Chr(13) & Chr(13) & "还需要文件操作控件", 16, "注意!")
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
S.Filter = ("文本文件(*.txt)|*.txt")
S.DefaultExt = "txt"
o.Filter = ("图形文件*.jpg|*.jpg|*.bmp|*.bmp")
o.DefaultExt = "jpg"
End Sub
End Class
练习:试开发一个记事本软件。
见,小小记事本,程序为:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ColorDialog1.ShowDialog()
TextBox1.ForeColor = ColorDialog1.Color
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
FontDialog1.ShowDialog()
TextBox1.Font = FontDialog1.Font
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim n As Integer
Dim f As String
SaveFileDialog1.ShowDialog()
f = SaveFileDialog1.FileName
n = FreeFile()
FileOpen(n, f, OpenMode.Output)
Print(n, TextBox1.Text)
FileClose(n)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OpenFileDialog1.Filter = "文本文件|*.txt"
SaveFileDialog1.Filter = "文本文件|*.txt"
OpenFileDialog1.DefaultExt = "txt"
SaveFileDialog1.DefaultExt = "txt"
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim fn As Integer
Dim s As String = ""
OpenFileDialog1.FileName = ""
If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
fn = FreeFile()
FileOpen(fn, OpenFileDialog1.FileName, OpenMode.Input)
Do While Not EOF(fn)
s = s + LineInput(fn) + vbCrLf
Loop
FileClose(fn)
TextBox1.Text = s
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
End
End Sub
最新更新
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
Python初学者友好丨详解参数传递类型
如何有效管理爬虫流量?
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
SQL Server -- 解决存储过程传入参数作为s
JavaScript判断两个数组相等的四类方法
js如何操作video标签
React实战--利用甘特图和看板,强化Paas平
【记录】正则替换的偏方
前端下载 Blob 类型整理
抽象语法树AST必知必会
关于JS定时器的整理
JS中使用Promise.all控制所有的异步请求都完
js中字符串的方法
import-local执行流程与node模块路径解析流程