emeriks
Goto Top

VB.Net - eigenes Control mit Smart Tags

Hi,
ich habe ein Problem mit selbsterstellten Controls unter VB.Net, bei denen ich eigene Smart Tags anhängen will.
Ich habe 2 Projekte: 1 Klassenbibliothek und 1 Windows Forms Projekt. Das Forms Projekt hat einen Verweis auf die Klassenbibkiothek.
So weit so gut.

Wenn ich in der DLL ein neues Control von System.Windows.Forms.Panel abgeleite ...
Public Class MyPanel
  Inherits System.Windows.Forms.Panel

End Class
.. dann kann ich dieses im Forms-Projekt in Formularen einfügen und ganz normal damit arbeiten. Also im Formular z.B. diesem Control dann weiter Unter-Controls hinzufügen. TextBoxen, Labels usw. Wie ein originales Panel halt.
Auch gut.

Jetzt verpasse ich meinem Panel-Control einen eigenen Smart Tag:
Imports System.Windows.Forms.Design
Imports System.ComponentModel.Design
Imports System.ComponentModel

<System.ComponentModel.Designer(GetType(MyPanelDesigner))> _
Public Class MyPanel
  Inherits System.Windows.Forms.Panel

End Class

Public Class MyPanelDesigner
  Inherits ControlDesigner

End Class

Wenn ich jetzt einer Form ein MyPanel-Control hinzufüge, dann kann ich diesem keine weiteren Unter-Controls per Drag&Drop hinzufügen.
Mache ich da was falsch? Habe ich was vergessen?

Eine eigene ActionList habe ich auch hinzugefügt. Ändert aber nichts.
Imports System.Windows.Forms.Design
Imports System.ComponentModel.Design
Imports System.ComponentModel
Imports System.Drawing

<System.ComponentModel.Designer(GetType(MyPanelDesigner))> _
Public Class MyPanel
  Inherits System.Windows.Forms.Panel

End Class

Public Class MyPanelDesigner
  Inherits ControlDesigner

 Private mActionListCollection As DesignerActionListCollection = Nothing

  Public Overrides ReadOnly Property ActionLists() As System.ComponentModel.Design.DesignerActionListCollection
    Get
      If mActionListCollection Is Nothing Then
        mActionListCollection = New DesignerActionListCollection()
        mActionListCollection.Add(New MyPanelActionList(Me.Control))
      End If

      Return mActionListCollection
    End Get
  End Property
End Class

Friend Class MyPanelActionList
  Inherits DesignerActionList

  Private mDesignerActionService As DesignerActionUIService = Nothing
  Private mMyPanel As MyPanel = Nothing

  Public Sub New(ByVal component As IComponent)
    MyBase.New(component)

    mMyPanel  = DirectCast(component, MyPanel )
    mDesignerActionService = CType(GetService(GetType(DesignerActionUIService)), DesignerActionUIService)
  End Sub

  Public Property PanelBackColor() As Color
    Get
      Return mMyPanel.BackColor
    End Get
    Set(ByVal Value As Color)
      mMyPanel.BackColor = Value
    End Set
  End Property

  Public Overrides Function GetSortedActionItems() As DesignerActionItemCollection
    Dim µItems As New DesignerActionItemCollection

    µItems.Add(New DesignerActionHeaderItem("Panel"))  

    µItems.Add(New DesignerActionPropertyItem("PanelBackColor", "Hintergrundfarbe", "Panel", "Liefert die Hintergrundfarbe des Panels oder legt diese fest."))  

    Return µItems
  End Function

End Class

Meine Frage:
Wie muss ich es anstellen, dass ich (wie in diesem Bsp.) einem von System.Windows.Forms.Panel abgleitetem Control eigene Smart Tags verpassen kann, ohne dabei im Designer die Funktionalität zu verlieren, dem Panel weitere Unter-Controls hinzufügen zu können?

E.

Content-Key: 256542

Url: https://administrator.de/contentid/256542

Printed on: April 16, 2024 at 21:04 o'clock