There are two scenarios for using SmartParts in a CAB application:
- The SmartPart required for a given location on a form is known at design time.
- The SmartPart is created and displayed dynamically at runtime, typically in response to user interaction.
To create a SmartPart
- Add a user control to your project.
- Add a reference to the Microsoft.Practices.CompositeUI.SmartParts namespace.
- Design the control to provide the appropriate appearance and functionality.
- Add the SmartPart attribute to the control class as shown in the following code.
[SmartPart]
public partial class MySmartPart : UserControl
To display a SmartPart dynamically at runtime, you can either allow a Workspace control to manage the positioning and dimensions of the SmartPart or you can explicitly designate an area in a form where the SmartPart will appear at runtime by using a SmartPartPlaceHolder control.
To display a SmartPart in a SmartPartPlaceholder
- Create an instance of the SmartPart user control using the AddNew method of the SmartParts or the Items collection of the WorkItem. You pass a string to the AddNew method to assign a name to the SmartPart. At runtime, the SmartPart is automatically loaded into the SmartPartPlaceHolder that specifies the SmartPart name for its SmartPartName property.
CustomerSmartPart csp;
csp = myWorkItem.SmartParts.AddNew("CustomerSP");
To display a SmartPart in a Workspace
- Create an instance of the SmartPart user control with the AddNew method of the SmartParts collection of the WorkItem.
- Call the Show method of the Workspace in which you want to show the SmartPart.
public class MyWorkItem : WorkItem
{
protected override void OnRunStarted()
{
base.OnRunStarted();
CustomerSmartPart csp = this.SmartParts.AddNew();
Workspaces["tabbedArea"].Show(csp);
}
}
No comments:
Post a Comment