vb.net编写控件 vbnet控件开发

VB.NET用TIMER控件我使用Visual Basic 2008 编写
1、新建2个窗体Form1和Form2
【vb.net编写控件 vbnet控件开发】2、Form1窗体新建一个Button按扭和一个Timer1控件
3、打开Form1编写如下代码
Public Class Form1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Form2.Show()
Me.Hide()'隐藏本窗体
Timer1.Enabled = False'使其只执行1次
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True'能使用其实这个在属性窗口中更容易设置
Timer1.Interval = 2000 '毫秒 即2秒
End Sub
End Class
vb.net怎么使用表格控件?DataGridView控件,放一个DataGridView1和Button1到窗体,下面是按钮下代码\x0d\x0aPrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click\x0d\x0aMe.DataGridView1.AllowUserToAddRows = False\x0d\x0aDataGridView1.RowTemplate.Height = 200\x0d\x0aDataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None\x0d\x0aFor i = 1 To 3\x0d\x0aMe.DataGridView1.Columns.Add("列"i.ToString, "列"i.ToString)\x0d\x0aMe.DataGridView1.Rows.Add()\x0d\x0aNext\x0d\x0aMe.DataGridView1.Columns(0).Width = 100\x0d\x0aMe.DataGridView1.Columns(1).Width = 500\x0d\x0aMe.DataGridView1.Columns(0).Width = 300\x0d\x0aEnd Sub\x0d\x0a'自己设置相关需要的属性即可
vb.net自定义控件问题首先vb.net编写控件,vb.net编写控件你已经完成的步骤是:
1.新建一个用户控件[注意,用户控件(UserControl)不是自定义控件(CustomControl)]
2.给用户控件起个名字(vb.net编写控件我在此处起名叫 RadioList)
3.在用户控件上画一个 GroupBox,命名为 RadioGroup,
并将其 Dock 属性设置为 Fill
然后,vb.net编写控件你需要做的是动态增减控件 。
如果你以前用过 VB 6,你可能会想到控件数组,
但在此处,你可以直接增删控件 。
具体实现如下:
4.在 GroupBox 里画一个 FlowLayoutPanel,命名为 RadioPanel ,
将其 AutoScroll 属性设置为 True,即自动显示滚动条,
并设置其 FlowDirection 属性(例如设置为 TopDown)
这样就省去了手动调整 RadioButton 位置的麻烦
5.实现选项的动态增减(以下只是我的思路 , 你可以发挥一下)
(十分简洁 , 注释除外):
''' summary
''' 创建一个新的 RadioButton 。
''' /summary
Private Function CreateRadio() As RadioButton
Dim NewRadio As New RadioButton
components.Add(NewRadio)
'components 字段由控件设计器自动创建,
'此代码目的是使控件在销毁(Dispose)时能自动销毁 RadioButton
'详情参见 RadioList.Designer.vb
NewRadio.Parent = RadioPanel
'设置容器
AddHandler NewRadio.CheckedChanged, AddressOf RadioButtons_CheckedChanged
'设置事件处理程序
Return NewRadio
End Function
''' summary
''' 移除已存在的 RadioButton 。
''' /summary
Private Sub RemoveRadio(ByVal dest As RadioButton)
components.Remove(dest)
dest.Dispose()
End Sub
'无中生有的 RadioButton 的事件处理程序
Private Sub RadioButtons_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
'在此处设置选中项的属性,通过 sender 来确定不同的 OptionButton
'你可以通过将 OptionButton 放在一个列表,
'如 List(Of OptionButton) 中来像数组一样维护选项的次序
'注意,此处需要判断 sender 的 Checked 属性是否为 True
'因为 Changed 是“改变” , 而不是“选中”
'例如:
If DirectCast(sender, RadioButton).Checked Then
SelectedIndex = ...
End If
End Sub
VB.NET中如何动态创建控件Option Explicit
Private WithEvents NewTextBox As TextBox
'通过使用WithEvents关键字声明一个对象变量为新的命令按钮
Private Sub Command1_Click()
If NewTextBox Is Nothing Then
Set NewTextBox = Controls.Add("VB.TextBox", "cmdNew", Form1)
NewTextBox.Move 200, 200
NewTextBox.Width = Form1.Width - 450
NewTextBox.Height = Form1.Height - 1400
NewTextBox.Visible = True
End If
End Sub
Private Sub Command2_Click()
If NewTextBox Is Nothing Then
Exit Sub
Else
Controls.Remove NewTextBox
Set NewTextBox = Nothing
End If
End Sub
VB.net 如何编写用户控件?Public Class UserControl1
#Region "变量"
Dim Down_Color As Color = Color.Blue
Dim UP_Color As Color = Color.Gray
Dim Mode As Short = 0
Dim flag As Boolean
Dim offset_X As Integer
Dim offset_Y As Integer
Dim Mouse_P As Point
#End Region
#Region "属性"
'按下颜色
Public Property _DownColor As Color
Get
Return Down_Color
End Get
Set(ByVal value As Color)
Down_Color = value
End Set
End Property
'弹起颜色
Public Property _UpColor As Color
Get
Return UP_Color
End Get
Set(ByVal value As Color)
UP_Color = value
End Set
End Property
'滑动模式 0-横 1-竖
Public Property _Mode As Short
Get
Return Mode
End Get
Set(ByVal value As Short)
Mode = value
End Set
End Property
#End Region
Private Sub UserControl1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.BackColor = UP_Color
End Sub
'鼠标按下
Private Sub UserControl1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
Me.BackColor = Down_Color
Mouse_P = e.Location
flag = True
End Sub
'鼠标移动
Private Sub UserControl1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If flag = False Then Exit Sub
Select Case Mode
Case 0'横向·
offset_X = e.X - Mouse_P.X
If Me.Location.Xoffset_XMe.Width = Me.ParentForm.Width Or Me.Location.Xoffset_X = 0 Then
flag = False
Else
Me.Location = New Point(Me.Location.Xoffset_X, Me.Location.Y)
End If
Case 1'竖向·
offset_Y = e.Y - Mouse_P.Y
If Me.Location.Yoffset_YMe.Height30 = Me.ParentForm.Height Or Me.Location.Yoffset_Y = 0 Then
flag = False
Else
Me.Location = New Point(Me.Location.X, Me.Location.Yoffset_Y)
End If
End Select
End Sub
'鼠标弹起
Private Sub UserControl1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
Me.BackColor = UP_Color
flag = False
End Sub
End Class
vb.net自定义控件mytest1是继承自什么类 , 通常应该继承自UerControl,虽然你这样也能编译通过,但实际上没有任何意义 。所以你先改了再说 。继承之后,编译 , 工具箱就会多这么个控件,拖动到Form1上,这样按钮下就不用再new了 。然后你再来问 。
关于vb.net编写控件和vbnet控件开发的介绍到此就结束了 , 不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。

    推荐阅读