Public Class UserControl1
創(chuàng)新互聯(lián)建站專注于企業(yè)全網(wǎng)營銷推廣、網(wǎng)站重做改版、龍子湖網(wǎng)站定制設(shè)計、自適應(yīng)品牌網(wǎng)站建設(shè)、H5建站、商城網(wǎng)站建設(shè)、集團公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站制作、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計等建站業(yè)務(wù),價格優(yōu)惠性價比高,為龍子湖等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
#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
添加一個TextBox控件(比如叫TextBox1)。
類似于Lable控件的功能,你可以修改TextBox控件的Text屬性來達到目的:
不是在設(shè)計器里修改,而是在代碼中用“TextBox1.Text="你想要顯示的字符串";”這樣的語句,這樣就可以在程序運行時改變顯示的內(nèi)容。
設(shè)置或者取消星號,你可以通過代碼修改TextBox1的PasswordChar屬性,跟上面的是類似的:
在其他的控件的事件中比如Button的Click事件中修改——“TextBox1.PasswordChar="";//不顯示***”
“TextBox1.PasswordChar="*(或者任何你想要的字符)";//顯示為***”
至于什么時候改就完全隨你的意思了。
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
mytest1是繼承自什么類,通常應(yīng)該繼承自UerControl,雖然你這樣也能編譯通過,但實際上沒有任何意義。所以你先改了再說。繼承之后,編譯,工具箱就會多這么個控件,拖動到Form1上,這樣按鈕下就不用再new了。然后你再來問。