用vs.net創(chuàng)建控件項目,其他的和vb類似...
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、小程序制作、集團企業(yè)網(wǎng)站建設(shè)等服務(wù)項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了賓縣免費建站歡迎大家使用!
新建項目-windows 窗體控件庫
先生成dataset,然后用datarow裝載dataset的需要編輯的記錄,再把datarow的值賦給textbox的text顯示給用戶編輯,用戶修改后,把textbox的text賦值回給datarow,最后update dataset更新數(shù)據(jù).
把你的控件 繼承Panel類,而不要集成UserControl類。
你可以在集成Panel后,往Panel里面加一些你自己的方法或Control來實現(xiàn)你需要的功能。向里面拖控件的功能則由Panel來控制,你自己就不用管了。
添加一個TextBox控件(比如叫TextBox1)。
類似于Lable控件的功能,你可以修改TextBox控件的Text屬性來達到目的:
不是在設(shè)計器里修改,而是在代碼中用“TextBox1.Text="你想要顯示的字符串";”這樣的語句,這樣就可以在程序運行時改變顯示的內(nèi)容。
設(shè)置或者取消星號,你可以通過代碼修改TextBox1的PasswordChar屬性,跟上面的是類似的:
在其他的控件的事件中比如Button的Click事件中修改——“TextBox1.PasswordChar="";//不顯示***”
“TextBox1.PasswordChar="*(或者任何你想要的字符)";//顯示為***”
至于什么時候改就完全隨你的意思了。
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