Public?Class?用戶控件

成都創(chuàng)新互聯(lián)公司是一家專注于成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、外貿(mào)營(yíng)銷網(wǎng)站建設(shè)與策劃設(shè)計(jì),會(huì)昌網(wǎng)站建設(shè)哪家好?成都創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設(shè)10余年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:會(huì)昌等地區(qū)。會(huì)昌做網(wǎng)站價(jià)格咨詢:18982081108
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
Get
Return UP_Color
End Get
Set(ByVal value As Color)
UP_Color = value
End Set
End Property
'滑動(dòng)模式 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
'鼠標(biāo)按下
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
'鼠標(biāo)移動(dòng)
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
'鼠標(biāo)彈起
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
關(guān)于用戶控件的使用,.net與v6環(huán)境下是有那么小小的區(qū)別。v6環(huán)境下的用戶控件編寫后可以直接使用,而在.net環(huán)境下,則需要先生成控件庫(dll,應(yīng)用程序擴(kuò)展格式),然后再將這個(gè)控件庫導(dǎo)入到.net編程環(huán)境的工具箱上方可使用。其具體方法如下(以VS 2010,Visual Basic.net 為例):1、新建項(xiàng)目-Visual Basic-Windows-Windows 窗體控件庫-鍵入控件庫名稱(默認(rèn)為Usercontrol1)確定;2、設(shè)計(jì)你的用戶控件,完成后按“F7”進(jìn)行編譯;3、在該解決方案目錄下找到控件庫擴(kuò)展(默認(rèn)為UserControl1.dll),確認(rèn)項(xiàng)目已經(jīng)生成。在上三項(xiàng)為控件庫DLL的生成方式,下面是調(diào)用方式:4、新建項(xiàng)目-Visual Basic-Windows-Windows 窗體應(yīng)用程序-確定;5、打開工具箱,以任意一個(gè)控件上點(diǎn)擊右鍵-選擇項(xiàng)-.net framework組件-瀏覽-定位到生成的控件庫擴(kuò)展-確定;6、在工具箱中找到新添加的用戶控件,將其拖至窗體中進(jìn)行設(shè)計(jì)。經(jīng)測(cè),在.net環(huán)境下編譯的用戶控件是通用的。也就是說使用Visual Basic.net編寫的用戶控件,也可以在C#工程里使用,反之亦然。這充分體現(xiàn)了.net語言的交互性,在我看來,.net下各種語言能力相當(dāng),它們都是作為一種中間語言,編譯出中間代碼。所以,在.net環(huán)境下,采用混合編程也未嘗不是一樣提高效率的一種可選的方式。
控件不一定有界面,類也不一定有界面。
以Visual Studio 2012為例
把你的控件封裝到類里面,生成exe或dll,在要調(diào)用的項(xiàng)目中,進(jìn)入工具箱,右鍵任意項(xiàng),選擇項(xiàng),在.Net Framework組件中瀏覽到生成的exe或dll,在上面列表中相應(yīng)的內(nèi)容,勾選,確定
文章題目:vb.net用戶控件制作,vb 控件
文章位置:http://chinadenli.net/article30/heocso.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號(hào)、全網(wǎng)營(yíng)銷推廣、網(wǎng)站收錄、關(guān)鍵詞優(yōu)化、網(wǎng)站改版、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)