VB.net 如何编写用户控件?
我VB6.写用户控件还是可以的,现在刚转到vb.net,需要将原来在VB6下开发的用户控件升级到VB.NET,在网上没找到比较好的资料,希望给个VB.net的用户控件的例...
我VB6.写用户控件还是可以的,现在刚转到vb.net,需要将原来在VB6下开发的用户控件升级到VB.NET,在网上没找到比较好的资料,希望给个VB.net的用户控件的例子,直接回答也行,给源代码也行,至少要包括一个例子(属性赋值,事件,方法)
邮箱 vbshare@163.com
先行谢过
补充一下:不懂VB.NET用户控件制作的不要在此灌水,谢谢 展开
邮箱 vbshare@163.com
先行谢过
补充一下:不懂VB.NET用户控件制作的不要在此灌水,谢谢 展开
2个回答
展开全部
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.X + offset_X + Me.Width >= Me.ParentForm.Width Or Me.Location.X + offset_X <= 0 Then
flag = False
Else
Me.Location = New Point(Me.Location.X + offset_X, Me.Location.Y)
End If
Case 1 '竖向·
offset_Y = e.Y - Mouse_P.Y
If Me.Location.Y + offset_Y + Me.Height + 30 >= Me.ParentForm.Height Or Me.Location.Y + offset_Y <= 0 Then
flag = False
Else
Me.Location = New Point(Me.Location.X, Me.Location.Y + offset_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
#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.X + offset_X + Me.Width >= Me.ParentForm.Width Or Me.Location.X + offset_X <= 0 Then
flag = False
Else
Me.Location = New Point(Me.Location.X + offset_X, Me.Location.Y)
End If
Case 1 '竖向·
offset_Y = e.Y - Mouse_P.Y
If Me.Location.Y + offset_Y + Me.Height + 30 >= Me.ParentForm.Height Or Me.Location.Y + offset_Y <= 0 Then
flag = False
Else
Me.Location = New Point(Me.Location.X, Me.Location.Y + offset_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与vb6.0有很大的区别
包含.nei类库
增加了面向对象思想
特别是面向对象思想
如继承 多态 类
除非你是有着C++或者java的编程经验
不然这东西还是比较难以理解的
而且语法也有很大的改变,还增加了数据类型
这些东西不是说用简单的属性赋值,事件与方法而完全说明的
也不可能用一个例子就说明了vb.net的语法等
如果你的打算是彻底的从vb6.0升级到.net的话 经验下载一本或者买本书全面系统的学习下
个人建议 仅供参考
微软新出的vb.net与vb6.0有很大的区别
包含.nei类库
增加了面向对象思想
特别是面向对象思想
如继承 多态 类
除非你是有着C++或者java的编程经验
不然这东西还是比较难以理解的
而且语法也有很大的改变,还增加了数据类型
这些东西不是说用简单的属性赋值,事件与方法而完全说明的
也不可能用一个例子就说明了vb.net的语法等
如果你的打算是彻底的从vb6.0升级到.net的话 经验下载一本或者买本书全面系统的学习下
个人建议 仅供参考
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询