Public?Class?用户控件
Inherits?System.Windows.Forms.Panel
Public?Sub?New()?'初始化
End?Sub?
Private?Sub?用户控件_KeyDown(sender?As?Object,?e?As?Forms.KeyEventArgs)?Handles?Me.KeyDown
'?......
End?Sub
'......
End?Class
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
Return UP_Color
UP_Color = value
'滑动模式 0-横 1-竖
Public Property _Mode As Short
Return Mode
Set(ByVal value As Short)
Mode = value
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
'鼠标移动
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
Me.Location = New Point(Me.Location.X, Me.Location.Y + offset_Y)
End Select
'鼠标弹起
Private Sub UserControl1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
End Class
控件不一定有界面,类也不一定有界面.
把你的控件封装到类里面,生成exe或dll,在要调用的项目中,进入工具箱,右键任意项,选择项,在.Net Framework组件中浏览到生成的exe或dll,在上面列表中相应的内容,勾选,确定
以上就是土嘎嘎小编为大家整理的vb.net用户控件制作相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!