Windows Develop Bookmark and Share   
 index > Windows Forms Designer > How to remove "Dock in Parent Container" SmartTag
 

How to remove "Dock in Parent Container" SmartTag

I have a Component I defined, it inherits from a Panel. There is a smart tag that appears called "Dock in Parent Container". How can I go about removing this?

I don't want my users changing the dock settings (stripped it out of the property box etc already).

FBNitro  Thursday, August 07, 2008 6:47 PM

Sorry, I spoke too quickly. The Dock item is added by an ActionItem list that is internal to ControlDesigner - I completely missed that, I apologize. So what I said above doesn't hold.

This DockingActionList is only added however, if the Component has a DockingAttributeBehavior different than None. So what you can do is simply set that on your Panel. Doing so might also take care of the other issues with Docking you are coding around (i.e. don't want users to set Docking).

I am not a VB expert, so pardon if this is not the best VB code.

Code Snippet

Public Class MyPanelDesigner

Inherits ParentControlDesigner

Public Overrides Sub Initialize(ByVal component As IComponent)

MyBase.Initialize(component)

End Sub

Public Overrides ReadOnly Property SelectionRules() As SelectionRules

Get

Return System.Windows.Forms.Design.SelectionRules.Locked

End Get

End Property

Protected Overrides Sub PostFilterAttributes(ByVal attributes As System.Collections.IDictionary)

MyBase.PostFilterAttributes(attributes)

Dim newAttribute As New DockingAttribute(DockingBehavior.Never)

attributes.Item(GetType(DockingAttribute)) = newAttribute

End Sub

End Class

Martin Thorsen - MSFT  Thursday, August 07, 2008 9:45 PM

The smart tag item is added by the ControlDesigner which checks if the underlying component has a Dock property. If so, then depending on the value (Fill or not), we add the Dock/Undock smart tag item.

You can get around this by overriding GetSortedActionItems in your control designer. Check out http://msdn.microsoft.com/en-us/library/ms171829(VS.80).aspx

Martin

Martin Thorsen - MSFT  Thursday, August 07, 2008 7:22 PM
Thanks for the response Martin, unfortunately I could not get that to work either. Based on what you said, I did the below code. (I probably did something wrong...). I also tried returning Nothing for the ActionLists in my ParentControlDesigner, but that still left the item there also.


<Designer(GetType(MyPanelDesigner))> _
Public Class MyPanel
Inherits Panel
...
End Class

Public Class MyPanelDesigner
Inherits ParentControlDesigner

Public Overrides Sub Initialize(ByVal component As IComponent)
MyBase.Initialize(component)
End Sub

Public Overrides ReadOnly Property SelectionRules() As SelectionRules
Get
Return System.Windows.Forms.Design.SelectionRules.Locked
End Get
End Property

Public Overrides ReadOnly Property ActionLists() As DesignerActionListCollection
Get
Dim list As New DesignerActionListCollection
list.Add(New MyActionList(Me.Component))
Return list
End Get
End Property

Private Class MyActionList
Inherits DesignerActionList

Sub New(ByVal Component As IComponent)
MyBase.New(Component)
End Sub

Public Overrides Function GetSortedActionItems() As DesignerActionItemCollection
Return New DesignerActionItemCollection()
End Function

End Class
End Class

FBNitro  Thursday, August 07, 2008 9:04 PM

Sorry, I spoke too quickly. The Dock item is added by an ActionItem list that is internal to ControlDesigner - I completely missed that, I apologize. So what I said above doesn't hold.

This DockingActionList is only added however, if the Component has a DockingAttributeBehavior different than None. So what you can do is simply set that on your Panel. Doing so might also take care of the other issues with Docking you are coding around (i.e. don't want users to set Docking).

I am not a VB expert, so pardon if this is not the best VB code.

Code Snippet

Public Class MyPanelDesigner

Inherits ParentControlDesigner

Public Overrides Sub Initialize(ByVal component As IComponent)

MyBase.Initialize(component)

End Sub

Public Overrides ReadOnly Property SelectionRules() As SelectionRules

Get

Return System.Windows.Forms.Design.SelectionRules.Locked

End Get

End Property

Protected Overrides Sub PostFilterAttributes(ByVal attributes As System.Collections.IDictionary)

MyBase.PostFilterAttributes(attributes)

Dim newAttribute As New DockingAttribute(DockingBehavior.Never)

attributes.Item(GetType(DockingAttribute)) = newAttribute

End Sub

End Class

Martin Thorsen - MSFT  Thursday, August 07, 2008 9:45 PM
That works perfectly, thank you! I didn't realize there was a DockingAttribute.
FBNitro  Thursday, August 07, 2008 10:01 PM

You can use google to search for other answers

Custom Search

More Threads

• Global DataSet - or Sharing Data between Forms
• Textbox Focus issue
• Is Generic UserControl supported by the designer?
• Change Smart Tag contents on the fly?
• Has the Ctrl+Tab behavior changed in visual studio?
• WinForms designer throws Exception when adding fillToolStrip component from DataSet without TableAdapters
• Problem with adding child controls
• Is there a way to switch between Design mode and View mode?
• Data Adapater Layout In Component Doesn't Persist
• TypeDescriptor.GetProperties and extenderproviders