Hosting user control in SOLIDWORKS Task Pane using SwEx.AddIn framework
Any System.Windows.Forms.UserControl can be hosted in the Task Pane by calling the ISwAddInEx.CreateTaskPane method.
MyControlHost ctrl; var taskPaneView = CreateTaskPane<MyControlHost>(out ctrl);
Both COM-visible and not COM-visible controls are supported
public partial class MyControlHost : UserControl { public IssuesControlHost() { InitializeComponent(); } } ... [ComVisible(true)] public partial class MyComVisibleControlHost : UserControl { public IssuesControlHost() { InitializeComponent(); } }
It is recommended to use COM-visible controls when hosting Windows Presentation Foundation (WPF) control in System.Windows.Forms.Integration.ElementHost as keypresses might not be handled properly in com-invisible controls.
Defining Commands
It is possible to define task pane commands to be added as buttons. It is required to declare the enumeration with commands and provides the commands handler.
public enum TaskPaneCommands_e { Command1 } ... TaskPaneControl ctrl; var taskPaneView = CreateTaskPane<TaskPaneControl, TaskPaneCommands_e>(OnTaskPaneCommandClick, out ctrl); ... private void OnTaskPaneCommandClick(TaskPaneCommands_e cmd) { switch (cmd) { case TaskPaneCommands_e.Command1: //TODO: handle command break; } }
Commands can be attributed with TitleAttribute and IconAttribute or TaskPaneIconAttribute for specifying the tooltip and icon respectively.
Standard icon can be set by using the TaskPaneStandardButtonAttribute attribute where the values defined in swTaskPaneBitmapsOptions_e enumeration
Please see the image below for the diagram of elements of Task Pane.
- WinForms User Control hosted in the Task Pane
- Task Pane button with the custom icon
- Task Pane button with default icon
- Task Pane button with standard swTaskPaneBitmapsOptions_Back icon
- Task Pane button with standard swTaskPaneBitmapsOptions_Next icon
- Task Pane button with standard swTaskPaneBitmapsOptions_Ok icon
- Task Pane button with standard swTaskPaneBitmapsOptions_Help icon
- Task Pane button with standard swTaskPaneBitmapsOptions_Options icon
- Task Pane button with standard swTaskPaneBitmapsOptions_Close icon
- Tooltip for Task Pane button
- Custom icon for Task Pane Tab
- Default icon for Task Pane Tab
- Tooltip for Task Pane Tab