emc3
2008-12-11 21:59:01 UTC
This is my first Custom Control / User Control in .NET, so please be patient
and detailed. Unfortunately, it appears I’ve jumped off into the deep end.
(For your sanity, I’ve explained the problem in detail…the current question
is at the bottom. Note that the environment is VS2005 and Framework 2.0 with
WinForms. I would have posted to the MSDN forums, but they're currently
moving the forum I need.)
Goal:
Create a custom UserControl that is a composite of a SplitContainer and a
TabControl. (I’m trying to approximate the functionality of the dockable,
pinnable windows in Visual Studio such as the Solution Explorer and
Properties windows. If there’s a better way, let me know.)
At design-time, the developer should be able to:
- Add other controls to the containers in this control (the split container
panels and tab pages).
- View and size the split panels using the splitter.
BackGround:
In order to get the tab control to properly display the tabs with the
Alignment property = “Right” I had to create a custom component implemented
inherited from TabControl and call SetWindowTheme as described in the
following thread:
http://social.msdn.microsoft.com/forums/en-US/Vsexpressvcs/thread/3b6f8ccb-f2d2-413b-ac1d-cd8def65e29a/
Public Class POCTabControl
Inherits TabControl
Private Declare Function SetWindowTheme Lib "uxtheme.dll" (ByVal hWnd As
IntPtr, Optional ByRef pszSubAppName As String = "", Optional ByRef
pszSubIdList As String = "") As Integer
Private Sub Initialize(ByVal sender As Object, ByVal e As EventArgs)
Handles Me.HandleCreated
SetWindowTheme(Me.Handle)
End Sub
End Class
I then created a custom UserControl “POCDockableWindowControl” and added a
SplitContainer control and then added the custom tab control “POCTabControl”
to the right SplitterPanel (Dock = Right, Alignment = Right).
At this point the UserControl “POCDockableWindowControl” compiles and can be
added to a test form. However, the next problem was that the control acts as
a single monolithic control at design-time…none of the individual controls
making up the composite control are selectable/editable, and attempting to
drag/drop any controls onto it results in the new controls being added to the
base form instead of a container in the UserControl.
I found another thread that helped me resolve the 2nd issue (adding
controls) by adding a Designer attribute of type ParentControlDesigner:
http://groups.google.com/group/microsoft.public.dotnet.framework.windowsforms.controls/browse_thread/thread/7e656e057ba5d179?hl=en
<System.ComponentModel.Designer(GetType(System.Windows.Forms.Design.ParentControlDesigner))> _
Public Class POCDockableWindowControl
End Class
So, I can now add controls to the containers at design-time (though I’m not
sure if they’re added to the UserControl container or a container within it
such as a SplitterPanel…how do I tell? I may have to re-visit this.).
Current Issues & Questions:
My problem is now to go further with being able to select the individual
controls within the composite control (at design-time) to be able to adjust
their properties (move the splitter to resize the splitterpanels, add tabs,
etc.). Currently, the splitter in the splittercontrol doesn’t even display
(there’s no dashed lines, or double-arrow on mouse-over).
I initially thought I needed to override some of the properties and methods
of the individual controls, but further research leads me to believe that I
should use the new methodology of creating a Custom Designer (utilizing
Adorners and Behaviors, etc.) to customize the design-time functionality. Is
this correct? The problem with this is that I can’t seem to find any examples
of creating a Custom Designer for a Composite control and have no experience
with Designers. (I’m assuming I want to create a single designer for the
composite rather than multiples for the individual controls comprising it.)
Has anyone done this or know of any examples I can review or download? Can
anyone recommend a good book that covers this in detail (Creating a Custom
Designer for Composite User Control)?
Hope you’ve made it this far ;-)
Thanks for any help!
-Ed
and detailed. Unfortunately, it appears I’ve jumped off into the deep end.
(For your sanity, I’ve explained the problem in detail…the current question
is at the bottom. Note that the environment is VS2005 and Framework 2.0 with
WinForms. I would have posted to the MSDN forums, but they're currently
moving the forum I need.)
Goal:
Create a custom UserControl that is a composite of a SplitContainer and a
TabControl. (I’m trying to approximate the functionality of the dockable,
pinnable windows in Visual Studio such as the Solution Explorer and
Properties windows. If there’s a better way, let me know.)
At design-time, the developer should be able to:
- Add other controls to the containers in this control (the split container
panels and tab pages).
- View and size the split panels using the splitter.
BackGround:
In order to get the tab control to properly display the tabs with the
Alignment property = “Right” I had to create a custom component implemented
inherited from TabControl and call SetWindowTheme as described in the
following thread:
http://social.msdn.microsoft.com/forums/en-US/Vsexpressvcs/thread/3b6f8ccb-f2d2-413b-ac1d-cd8def65e29a/
Public Class POCTabControl
Inherits TabControl
Private Declare Function SetWindowTheme Lib "uxtheme.dll" (ByVal hWnd As
IntPtr, Optional ByRef pszSubAppName As String = "", Optional ByRef
pszSubIdList As String = "") As Integer
Private Sub Initialize(ByVal sender As Object, ByVal e As EventArgs)
Handles Me.HandleCreated
SetWindowTheme(Me.Handle)
End Sub
End Class
I then created a custom UserControl “POCDockableWindowControl” and added a
SplitContainer control and then added the custom tab control “POCTabControl”
to the right SplitterPanel (Dock = Right, Alignment = Right).
At this point the UserControl “POCDockableWindowControl” compiles and can be
added to a test form. However, the next problem was that the control acts as
a single monolithic control at design-time…none of the individual controls
making up the composite control are selectable/editable, and attempting to
drag/drop any controls onto it results in the new controls being added to the
base form instead of a container in the UserControl.
I found another thread that helped me resolve the 2nd issue (adding
controls) by adding a Designer attribute of type ParentControlDesigner:
http://groups.google.com/group/microsoft.public.dotnet.framework.windowsforms.controls/browse_thread/thread/7e656e057ba5d179?hl=en
<System.ComponentModel.Designer(GetType(System.Windows.Forms.Design.ParentControlDesigner))> _
Public Class POCDockableWindowControl
End Class
So, I can now add controls to the containers at design-time (though I’m not
sure if they’re added to the UserControl container or a container within it
such as a SplitterPanel…how do I tell? I may have to re-visit this.).
Current Issues & Questions:
My problem is now to go further with being able to select the individual
controls within the composite control (at design-time) to be able to adjust
their properties (move the splitter to resize the splitterpanels, add tabs,
etc.). Currently, the splitter in the splittercontrol doesn’t even display
(there’s no dashed lines, or double-arrow on mouse-over).
I initially thought I needed to override some of the properties and methods
of the individual controls, but further research leads me to believe that I
should use the new methodology of creating a Custom Designer (utilizing
Adorners and Behaviors, etc.) to customize the design-time functionality. Is
this correct? The problem with this is that I can’t seem to find any examples
of creating a Custom Designer for a Composite control and have no experience
with Designers. (I’m assuming I want to create a single designer for the
composite rather than multiples for the individual controls comprising it.)
Has anyone done this or know of any examples I can review or download? Can
anyone recommend a good book that covers this in detail (Creating a Custom
Designer for Composite User Control)?
Hope you’ve made it this far ;-)
Thanks for any help!
-Ed