Если вы хотите, вы можете скрыть свой элемент управления от видимости в панели инструментов
<System.ComponentModel.ToolboxItem(False)> _
Public Class SuicideCustomButton
Inherits Button
...
End Class
Обновление:
Это новая версия, это умный материал, который спрашиваетВы хотите ввести пароль в режиме конструктора, и если вы хотите создать экземпляр по коду (без дизайнера), вам следует передать пароль конструктору:
Public Class SuicideCustomButton
Inherits Button
Dim KillMeOut As Boolean = False
Private _Pass As String
Public Property Pass() As String
Get
Return _Pass
End Get
Set(ByVal value As String)
_Pass = value
End Set
End Property
Protected Overrides Sub OnLocationChanged(ByVal e As System.EventArgs)
MyBase.OnLocationChanged(e)
' In Design mode this is required
If DesignMode AndAlso KillMeOut AndAlso Me.Parent IsNot Nothing AndAlso Me.Parent.Controls.Contains(Me) Then
Me.Parent.Controls.Remove(Me)
End If
End Sub
Protected Overrides Sub InitLayout()
MyBase.InitLayout()
If Pass <> "xpass" Then
If Not DesignMode AndAlso Not KillMeOut AndAlso Me.Parent IsNot Nothing AndAlso Me.Parent.Controls.Contains(Me) Then
Throw New Exception("You can't add this object in without a password :)")
Else
If Not PassInputFrm.Pass Then
KillMeOut = True
Else
Pass = "xpass"
End If
End If
End If
End Sub
''' <summary>
''' This will be used in design mode
''' </summary>
Public Sub New()
End Sub
''' <summary>
''' Use this constructor in code mode
''' </summary>
Public Sub New(ByVal pass As String)
If Not PassInputFrm.ValidatePass(pass) Then
KillMeOut = True
Else
pass = "xpass"
End If
End Sub
End Class
Вам понадобится форма для ввода пароля, поэтому я ее создаю.и загрузите его здесь