vb.net编写一个控件 vbnet ui

VB.net 如何编写用户控件?

Public Class UserControl1

创新互联建站专注于企业全网营销推广、网站重做改版、龙子湖网站定制设计、自适应品牌网站建设、H5建站商城网站建设、集团公司官网建设、成都外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为龙子湖等各大城市提供网站开发制作服务。

#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的知识制作带*的文本框控件

添加一个TextBox控件(比如叫TextBox1)。

类似于Lable控件的功能,你可以修改TextBox控件的Text属性来达到目的:

不是在设计器里修改,而是在代码中用“TextBox1.Text="你想要显示的字符串";”这样的语句,这样就可以在程序运行时改变显示的内容。

设置或者取消星号,你可以通过代码修改TextBox1的PasswordChar属性,跟上面的是类似的:

在其他的控件的事件中比如Button的Click事件中修改——“TextBox1.PasswordChar="";//不显示***”

“TextBox1.PasswordChar="*(或者任何你想要的字符)";//显示为***”

至于什么时候改就完全随你的意思了。

请教vb.net怎么制作一个可以作为容器的用户控件

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

vb.net自定义控件

mytest1是继承自什么类,通常应该继承自UerControl,虽然你这样也能编译通过,但实际上没有任何意义。所以你先改了再说。继承之后,编译,工具箱就会多这么个控件,拖动到Form1上,这样按钮下就不用再new了。然后你再来问。


标题名称:vb.net编写一个控件 vbnet ui
分享地址:http://hbruida.cn/article/dopsihd.html