vb.net怎么写类控件 vbnet常用控件介绍

VB.NET 如何做 控件

用vs.net创建控件项目,其他的和vb类似...

创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都网站设计、做网站、冀州网络推广、小程序定制开发、冀州网络营销、冀州企业策划、冀州品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联为所有大学生创业者提供冀州建站搭建服务,24小时服务热线:13518219792,官方网址:www.cdcxhl.com

新建项目-windows 窗体控件库

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 如何在一个项目中创建类,并且使用他?

在任意form类或模块中都可以创建类,跟建立函数和过程一样。

示例:

public class form1

‘创建一个属于form的子类,名称为【类名】。

public class 类名

’定义类成员text

public text as string

end class

‘定义一个【类名】类的公共变量。

dim 类名1 as 类名

’定义一个过程,使用【类名】类的text成员

public sub 过程

‘实例化【类名1】

类名1=new 类名

类名1.text=“赋值”

’定义一个【新类】类的私用变量,并实例化。

dim 新类1 as new 新类

新类1.name=“一个字符串”

新类1.age=12

end sub

end class

‘’‘创建一个与form同级的类,名称为【新类】

public class 新类

public sub new()

end sub

public name as string

public age as integer

end class

在模块中使用:

public class module1

dim a as new form1.类名

end module

你好,我想请教一下vb.net中怎么调用用户控件,谢谢!

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

首先添加引用。

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

接着就可以使用了:

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

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

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

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

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

网页标题:vb.net怎么写类控件 vbnet常用控件介绍
网站链接:https://www.cdcxhl.com/article26/doejgjg.html

成都网站建设公司_创新互联,为您提供企业建站网站策划软件开发虚拟主机App开发做网站

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

营销型网站建设