vb.net创建用户控件 VB常用控件

vb.net如何创建无界面的用户控件

控件不一定有界面,类也不一定有界面。

宿迁网站制作公司哪家好,找成都创新互联!从网页设计、网站建设、微信开发、APP开发、响应式网站等网站项目制作,到程序开发,运营维护。成都创新互联从2013年创立到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选成都创新互联

以Visual Studio 2012为例

把你的控件封装到类里面,生成exe或dll,在要调用的项目中,进入工具箱,右键任意项,选择项,在.Net Framework组件中浏览到生成的exe或dll,在上面列表中相应的内容,勾选,确定

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.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中怎么调用用户控件,谢谢!

与使用System.Windows.Forms命名空间中的控件的用法没有区别。

首先添加引用。

其次导入(Imports)命名空间。

接着就可以使用了:

1、要使用用户控件的实例成员,就先创建一个用户控件的实例,再通过实例名.实例成员名访问;

2、要使用用户控件的共享(Shared)成员,通过用户控件类名.共享成员名访问。

如果你问的是怎样创建自己的用户控件类:

1、继承类System.Windows.Forms.UserControl;

2、继承任何一个已经存在的控件类(只要这个控件类不是NotInheritable的就行)。


文章名称:vb.net创建用户控件 VB常用控件
网页网址:http://hbruida.cn/article/hghgei.html