Button
1.FlatStyle 平面样式外观 将鼠标移动到控件上并单击时该控件的外观
Me.Button1.FlatStyle = FlatStyle.Flat
Popup 三维 Standard 外观为三维
2.Cursor 鼠标样式
Me.Button1.Cursor = Cursors.Hsplit
CheckBox
Location() 获取位置 Size() 获取长(height)与宽(width) Hide() Show()
Dim s As String = "您的爱好是:" & vbCrLf
For Each ch As Object In Me.Controls
If ch.GetType.ToString() = "System.Windows.Forms.CheckBox" Then
ch = CType(ch, CheckBox)
If ch.Checked Then
s = s + ch.Text + vbNewLine
End If
End If
Next
MessageBox.Show(s)
CheckedListBox
Dim s As String = "您的兴趣为:" & vbCrLf
For Each f As Object In Me.CheckedListBox1.CheckedIndices ‘获取所有项
‘把被设成 "Checked" 的项放到s里
If CStr(Me.CheckedListBox1.GetItemCheckState(f).ToString()) = "Checked" Then
s = s + Me.CheckedListBox1.Items(f) + vbNewLine
End If
Next
MessageBox.Show(s)
ComboBox
SelectedItem 被选择的项目
SelectedIndex 被选择项目的索引
DropDownStyle 组合框的下拉样式
DropDown 可编辑样式
DropDownList 不可编辑样式
Simple 文本框样式,只显示当前部分可编辑
Items.Insert(I,O) 在第I个位置插入选项O
Items.Clear( ) 清除所有项目
SelectedIndexChangede 所选项目发生改变时触发
LinkLabel
1.带链接的标签
LinkLabel1.Text = "Google搜寻引擎. Yahoo奇摩拍卖. MSN."
2.标签内部 从开始位置/结束位置进行链接
LinkLabel1.Links.Add(0, 6, "http://www.google.com")
LinkLabel1.Links.Add(12, 5, "http://tw.bid.yahoo.com")
LinkLabel1.Links.Add(23, 3, "http://www.msn.com")
3.获取内部链接的数据,转换成字符(获取链接的字符)/系统进行链接
Dim lj As String = CType(e.Link.LinkData, String)
System.Diagnostics.Process.Start(lj)
DateTimePicker日期时间控件
CustorFormat 设置格式 Format(DateTimePicker2.Value, " HH:mm:ss"))
ShowUpDown 是否显示下拉菜单
DateTimePicker1.Format = DateTimePickerFormat.Short
日期时间样式
DateTimePickerFormat.Custom /(Short) 2008-5-14
DateTimePickerFormat.Long 2008年5月14日
DateTimePickerFormat.Time 13:00:21
下限时间/上限时间
DateTimePicker1.MinDate = New DateTime(2006, 1, 1)
DateTimePicker1.MaxDate = New DateTime(2050, 12, 31)
MsgBox("你购买本书的日期为: " & DateTimePicker1.Value.ToShortDateString() & Format(DateTimePicker2.Value, " HH:mm:ss"))
DateTimePicker1.Value.ToShortDateString() 转化成:
Format(DateTimePicker2.Value, " HH:mm:ss")) 格式为:
Timer
Timer1.Interval = txt_interval.Text
Timer1.Start()
Timer1.Stop()
MonthCalendar月历控件
1. CalendarDimensions 所选月份的行数和列数 即几行几列显示
Me.MonthCalendar1.CalendarDimensions = New System.Drawing.Size(1, 1)
2.月历中一周的第一天是星期几 FirstDayOfWeek
Me.MonthCalendar1.FirstDayOfWeek = Day.Monday
3.所选月历的上限日期/下限日期
Me.MonthCalendar1.MaxDate = New System.DateTime(2030, 12, 31)
Me.MonthCalendar1.MinDate = New System.DateTime(2006, 1, 1)
4.在左侧是否显示本周在一年中的周数即本周是一年中的第多少周
MonthCalendar1.ShowWeekNumbers = True
5.底端是否显示提示信息
Me.MonthCalendar2.ShowToday = True
MaskTextBox
Mask 系统自带几种掩码
0 只会接受0到9之间的数字
# 接收数字和空格,允许使用 +号 —号
L( ? ) 只会接收A—Z(a—z)之间的英文字母
. 小数点预留位置 : 时间分隔符 $ 货币符号
BeepOnError 当用户输入错误格式时发出警告声音
MaskFull 是否已经输入了所有字段值 完成返回True
Clear清除所有字符串 MaskInputRejected 用户输入与设置格式不相符时触发
Me.MaskedTextBox_Birth.Mask = "00/00/0000"
Me.MaskedTextBox_Name.Mask = "LLLLLLLLLLLLLLLLLLLL"
RichTextBox文本编辑
SelectionColor SelectionFont SelectionBackColor Find( ) Copy( ) 复制到剪贴版
加载文件
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.RichTextBox1.LoadFile("C:\Documents and Settings\Administrator\桌面\123.txt", RichTextBoxStreamType.PlainText)
End Sub
保存文件
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.RichTextBox1.SaveFile("C:\Documents and Settings\Administrator\桌面\987.txt", RichTextBoxStreamType.PlainText)
End Sub
查找文件
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Try
Me.RichTextBox1.Find(Me.TextBox1.Text)
Me.RichTextBox1.SelectionColor = Color.Red
Catch ex As Exception
End Try
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.ComboBox1.SelectedIndex = 0
Me.ComboBox2.SelectedIndex = 0
Me.ComboBox3.SelectedIndex = 0
End Sub
改变样式:字体大小Cint 字体颜色 字体名称
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Try
Select Case Me.ComboBox3.SelectedItem
Case "红色"
Me.RichTextBox1.SelectionColor = Color.Red
Case "黄色"
Me.RichTextBox1.SelectionColor = Color.Yellow
Case "黑色"
Me.RichTextBox1.SelectionColor = Color.Black
Case "绿色"
Me.RichTextBox1.SelectionColor = Color.Green
End Select
Me.RichTextBox1.SelectionFont=New Font(Me.ComboBox2.SelectedItem.ToString, CInt(Me.ComboBox1.SelectedItem.ToString), FontStyle.Bold)
Me.RichTextBox1.SelectionColor = Me.RichTextBox1.SelectionColor
Catch ex As Exception
End Try
End Sub
RadioButton
For Each rb As Object In Me.Controls
If rb.GetType.ToString() = "System.Windows.Forms.RadioButton" Then
rb = CType(rb, RadioButton)
If rb.Checked Then
MsgBox("您选择的身高为: " & rb.Text)
End If
End If
Next
GroupBox
Controls.Add( ) 可以直接在代码中添加项目
GroupBox_sex.Controls.Add(RadioButton_man)
GroupBox_blood.Controls.Add(RadioButton_A)
ImgList
1.添加Images.Add( ) Images.Clear( )清除所有图像
Dim ImgList As New ImageList
ImgList.Images.Add(Image.FromFile("..\..\img\EMAIL003.ICO"))
2.大小ImageSize
ImgList.ImageSize = New System.Drawing.Size(50, 50)
3.
ToolStrip1.ImageList = ImgList
PictureBox
BackColor 背景颜色 BackGroundImage 背景图片 InitialImage初始图片
Location.X 最左边的位置 Location.Y 最上方的位置 SizeMode 图片的显示方式
Zoom 根据长宽比缩放 StretchImage 把图片调整成控件大小 Normal 对齐控件左上角
Me. PictureBox1.Image=Image.FromFile(“”)
Me. PictureBox1. SizeMode= PictureBox SizeMode.Zoom
ErrorProvider
'闪烁的时间
Me.ErrorProvider1.BlinkRate = 1
'闪烁的样式
Me.ErrorProvider1.BlinkStyle = ErrorBlinkStyle.AlwaysBlink
'位置
Me.ErrorProvider1.SetIconAlignment(Me.TextBox1, ErrorIconAlignment.MiddleRight)
'与文本框间的距离
Me.ErrorProvider1.SetIconPadding(Me.TextBox1, 0)
If Me.TextBox1.Text = "" Then
ErrorProvider1.SetError(Me.TextBox1, "请勿空白")
If MessageBox.Show("请勿空白", "友情提示", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
Me.ErrorProvider1.Clear()
End If
End If
HelpButton
'右上角是否显示帮助图标
Me.HelpButton = True
'按F1帮助按钮打开网页
HelpProvider1.HelpNamespace = "..\..\index.htm"
'按命令按钮如同按F1键打开网页HelpProvider1.SetShowHelp(Me.Button1, True)
在文本框中是否显示提示信息
HelpProvider1.SetHelpString(Me.TextBox1, "请在此输入您的出生年月日")
ProgressBar
Minimum 最小值 Maximum最大值 Value初始值
Me.ProgressBar1.Minimum = 0
Me.ProgressBar1.Maximum = 9999999
Dim i
Me.ProgressBar1.Value = 0
For i = Me.ProgressBar1.Minimum To Me.ProgressBar1.Maximum
Me.ProgressBar1.Increment(1)
Next
Me.ProgressBar1.Style = ProgressBarStyle.Continuous
ContextMenuStrip右键菜单
1.先设置菜单
ContextMenuStrip1.Items.Add("Mitubishi-Eclipes")
2.然后在窗体加载时
Me.ContextMenuStrip = Me.ContextMenuStrip1
3.选择单击时ContextMenuStrip1_ItemClicked()
Private Sub ContextMenuStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles ContextMenuStrip1.ItemClicked
PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
Dim pic_Eclipse As Image = Image.FromFile("..\..\pic\Eclipse.jpg")
Dim pic_Evo As Image = Image.FromFile("..\..\pic\Evo.jpg")
Dim pic_Mx5 As Image = Image.FromFile("..\..\pic\Mx5.jpg")
Dim pic_Rx8 As Image = Image.FromFile("..\..\pic\Rx8.jpg")
Select Case e.ClickedItem.Text
Case "Mitubishi-Eclipes"
PictureBox1.Image = pic_Eclipse
Case "Mitubishi-EVO"
PictureBox1.Image = pic_Evo
Case "Mazda-MX5"
PictureBox1.Image = pic_Mx5
Case "Mazda-RX8"
PictureBox1.Image = pic_Rx8
End Select
End Sub
DataGridView
1.单元格行的改变
RowsDefaultCellStyle 行的默认样式
AlternatingRowsDefaultCellStyle 奇数行的默认样式
Me.DataGridView1.RowsDefaultCellStyle.BackColor = Color.AliceBlue
Me.DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Ivory
2.单元格的自动调整 AutoResizeRows 所有行的高度
DataGridView1.AutoResizeRows()
3.单元格的边框样式
Me.DataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.SingleHorizontal
行标题的单元格样式
Me.DataGridView1.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Sunken
列标题的单元格样式
Me.DataGridView1.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
4.改变字段标头名称
DataGridView1.Columns(0).HeaderText = "使用者编号"
DataGridView1.Columns(1).HeaderText = "昵称"
DataGridView1.Columns(2).HeaderText = "照片"
5.隐藏数据行行首
DataGridView1.ColumnHeadersVisible = False
6.改变字段选择模式
SortMode 排序模式
SelectionMode
FullColumnSelect 按列的模式整体选择
FullRowSelect 按行的模式整体选择
RowHeaderSelect 单击字段进行选中
Dim i As Integer = 0
For i = 0 To DataGridView1.Columns.Count - 1
Me.DataGridView1.Columns(i).SortMode = DataGridViewColumnSortMode.NotSortable
Next
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullColumnSelect
7.显示被选取的数据行位置与总数
'注意DataGridView的SelectMode只能为选取字段或选取数据列 不能二者同时存在
'先确定DataGridView的Column集合中所有字段属性SortMode要改为NotSortable
'然后设定DataGridView的SelectMode为FullColumnSelect或ColumnHeaderSelect
'获取选取数据行(Column)的总数
Dim selectedColumnCount As Integer = DataGridView1.Columns.GetColumnCount(DataGridViewElementStates.Selected)
If (selectedColumnCount > 0) Then
Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder()
Dim i As Integer = 0
For i = 0 To selectedColumnCount - 1
sb.Append("字段(Column): ")
sb.Append(DataGridView1.SelectedColumns(i).Index.ToString())
sb.Append(" " & DataGridView1.SelectedColumns(i).DataPropertyName.ToString())
sb.Append(Environment.NewLine)
Next
sb.Append("选取字段(Column)总数: " + selectedColumnCount.ToString())
MessageBox.Show(sb.ToString(), "选取数据行(Columns)")
End If
8.设定UserID字段不可排序
Me.DataGridView1.Columns("UserID").SortMode = DataGridViewColumnSortMode.NotSortable
9.防止在DataGridView控制项中新增和删除数据列
DataGridView1.AllowUserToAddRows = False
DataGridView1.AllowUserToDeleteRows = False
ColorDialog
1.AllowFullOpen 用户是否可以使用该对话框定义颜色
Dim ColorDialog1 As New ColorDialog()
Me.ColorDialog1.AllowFullOpen = True
2.是否显示帮助按钮
Me.ColorDialog1.ShowHelp = True
3.添加到自定义颜色控件是否可见 如只要颜色则改成False
Me.ColorDialog1.FullOpen = True
4.打开颜色对话框
ColorDialog1.ShowDialog()
FontDialog
MaxSize 所能选择字号的最大值 MinSize 所能选择字号的最大值
1. ShowEffects 是否有删除线,下划线
Dim FontDialog1 As New FontDialog
FontDialog1.ShowEffects = True
2.是否有帮助按钮 ShowHelp
FontDialog1.ShowHelp = True
3.打开字体对话框
FontDialog1.ShowDialog()
4.Reset 返回为默认值
5.设置获取字体
RBox.SelectionFont = FontDialog1.Font
OpenFileDialog
Filter打开文件的格式 InitialDirectory初始化目录
RestoreDirectory 关闭前的目录 Multiselect 是否支持打开多重文件
ShowReadOnly 是否显示“以只读方式打开文件”
Title 显示的标题 FilterIndex 目前选择的文件格式
FileName所选择的文件名 FileNames 所选择的所有文件的文件名,以数组方式
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.InitialDirectory = "..\..\rtf"
openFileDialog1.Filter = "RichTextBox files (*.rtf)|*.rtf"
openFileDialog1.FilterIndex = 1
openFileDialog1.ShowDialog()
RBox.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.RichText)
SaveFileDialog
1. InitialDirectory 显示的初始目录 CheckPathExists 是否显示“目录不存在”
Dim SaveFileDialog1 As New SaveFileDialog()
SaveFileDialog1.InitialDirectory = "..\..\rtf"
2.保存的文件类型
SaveFileDialog1.Filter = "RichTextBox files (*.rtf)|*.rtf"
3.打开
SaveFileDialog1.ShowDialog()
4.保存
RBox.SaveFile(SaveFileDialog1.FileName, RichTextBoxStreamType.RichText)
PrintDialog
1.AllowCurrentPage “当前页面选项”选项 AllowPrintToFile “打印到文件选项”
AllowSelection “选定范围” 选项 AllowSomePages 可选择的页面选项
ShowHelp “说明”选项 ShowNetwork “网络”选项
AllowSomePages 页码选项
PrintDialog1.AllowSomePages = True
2.AllowCurrentPage 当前页面选项
PrintDialog1.AllowCurrentPage = True
3.打开
PrintDialog1.ShowDialog()
WebBrowser
1.如在文本框中输入
http://www.lihuaedu.com 则显示为链接样式
2.是否有滚动条
Me.WebBrowser1.ScrollBarsEnabled = True
3.已经打开新的网页时触发
Me.WebBrowser1.Navigate(Me.TextBox1.Text)
4.返回上一页
WebBrowser1.GoBack()
"下一页"
WebBrowser1.GoForward()
"返回首页"
WebBrowser1.GoHome()
"刷新"
WebBrowser1.Refresh()
"停止"
WebBrowser1.Stop()
"搜索"
WebBrowser1.GoSearch()
"打印预览当前页"
WebBrowser1.ShowPrintPreviewDialog()
"查看内容"
WebBrowser1.ShowPropertiesDialog()
打开"打印"对话框
WebBrowser1.ShowPrintDialog()
打开"属性"对话框
WebBrowser1.PropertiesDialog()
5.文本框获取网页中的URL的字符串
TextBox1.Text = WebBrowser1.Document.Url.ToString
6.网页获取列表框中的选择项目
WebBrowser1.Navigate(ListBox1.SelectedItem.ToString)
7.网页获取链接标签中的数据源字符串e.Link.LinkData.ToString
WebBrowser1.Navigate(e.Link.LinkData.ToString)
8.将网页中的网址字符串添加到列表框中
ListBox1.Items.Add(CStr(WebBrowser1.Document.Url.ToString()))
ListView
1.Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lv_bd()
Me.ListView1.Activation = ItemActivation.TwoClick
'显示的方式列表显示
Me.ListView1.View = View.List(不显示图片)
'当要显示标头时
Me.ListView1.View = View.Details
ListView1.Columns.Add("目录名称", -2, HorizontalAlignment.Left)
End Sub
Private Sub lv_bd()
'首先把文本传过去给s过程
s("系统管理")
'再把要加载图像传过去的第一层文本传给f过程
Me.ListView1.LargeImageList = f("系统管理")
Me.ListView1.View = View.LargeIcon
End Sub
2.处理层中的文本
Private Sub s(ByVal a As String)
Select Case a
Case "系统管理"
Me.ListView1.Items.Add("计算机")
Me.ListView1.Items.Add("网络开发")
Me.ListView1.Items.Add("软件开发")
Case Else
End Select
End Sub
3.处理层中的图像
Private Function f(ByVal a As String) As ImageList
Dim imglist As New ImageList
Dim imgsize As System.Drawing.Size
imgsize.Height = 40
imgsize.Width = 40
imglist.ImageSize = imgsize
Select Case a
Case "系统管理"
imglist.Images.Add(Image.FromFile("..\..\img\A01.ico"))
imglist.Images.Add(Image.FromFile("..\..\img\A02.ico"))
imglist.Images.Add(Image.FromFile("..\..\img\A03.ico"))
Case Else
End Select
4.返回加载好的图像
For i As Integer = 0 To Me.ListView1.Items.Count - 1
Me.ListView1.Items.Item(i).ImageIndex = i
Next
Return imglist
End Function
5.制作下一层
ListView1_ItemActivate()过程中
Select Case Me.ListView1.SelectedItems(0).Text
Case "计算机"
s("计算机")
f("计算机") [如果不想写此代码还可以在s过程中的多条件选择中键入:Me.ListView1.LargeImageList = f("计算机")]
case else
Case Else
End Select
TreeView
Nodes.Add() 第一层结点
TView.Nodes.Add("主画面")
Nodes(0).Nodes.Add() 第二层的结点
TView.Nodes(0).Nodes.Add("人员注册管理")
TView.Nodes(0).Nodes.Add("招生系统管理")
TView.Nodes(0).Nodes.Add("教务管理")
Nodes(0).Nodes(0).Nodes.Add第三层结点
TView.Nodes(0).Nodes(0).Nodes.Add("学生资料管理")
‘图标处理
1. Dim imglist As New ImageList
imglist.Images.Add(Image.FromFile("..\..\img\A01.ico"))
imglist.Images.Add(Image.FromFile("..\..\img\B01.ico"))
imglist.Images.Add(Image.FromFile("..\..\img\C01.ico"))
2.
TView.Nodes(0).Nodes.Item(0).ImageIndex = 0
TView.Nodes(0).Nodes(0).Nodes.Item(0).ImageIndex = 1
TView.Nodes(0).Nodes(0).Nodes.Item(1).ImageIndex = 2
TView.Nodes(0).Nodes.Item(1).ImageIndex = 3
TView.Nodes(0).Nodes.Item(2).ImageIndex = 4
3.
TView.Nodes(0).Nodes.Item(0).SelectedImageIndex = 0
TView.Nodes(0).Nodes(0).Nodes.Item(0).SelectedImageIndex = 1
TView.Nodes(0).Nodes(0).Nodes.Item(1).SelectedImageIndex = 2
TView.Nodes(0).Nodes.Item(1).SelectedImageIndex = 3
TView.Nodes(0).Nodes.Item(2).SelectedImageIndex = 4