
正文
vb.net自己写控件 vbnet自定义控件
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
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
相关问答
Q1: vb.net 自定义控件 GROUPBOX 容器
缓存刷新vb.net自己写控件了vb.net自己写控件,vb.net自己写控件你需要在缓存区建立一个Image对象来存放所有绘制的Graphics对象,再将Image对象显示在GroupBox容器中即可。
Q2: vb.net自定义控件
mytest1是继承自什么类vb.net自己写控件,通常应该继承自UerControl,虽然你这样也能编译通过,但实际上没有任何意义。所以你先改vb.net自己写控件了再说。继承之后,编译,工具箱就会多这么个控件,拖动到Form1上,这样按钮下就不用再new了。然后你再来问。
Q3: VB.NET自定义控件的问题
1.
web.config里注册,类似下面
system.web
pages
controls
add tagPrefix="scottgu" src="~/Controls/Header.ascx" tagName="header"/
add tagPrefix="scottgu" src="~/Controls/Footer.ascx" tagName="footer"/
/controls
/pages
/system.web
注意这里的路径一定不能错,否则显示不出来
2.
注册用户控件时使用绝对路径,而不是相对路径
关于vb.net自己写控件和vbnet自定义控件的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。








