SmartPartPlaceholder instead of Workspace?

Topics: CAB & Smart Client Software Factory
Jan 10, 2006 at 2:39 PM
originally posted by: CSain

I am having trouble understanding how to use the SmartPartPlaceholder control. Is it possible to rewrite the code in the Walkthrough to use a SmartPartPlaceholder to host MyView directly in ShellForm instead of the SplitContainer and TabbedWorkspace? If so, how would I do that?
Jan 14, 2006 at 8:44 PM
originally posted by: amishah_2001

To display a SmartPart dynamically at runtime, you can either allow a Workspace control to manage the positioning and dimensions of the SmartPart (for example, in a TabWorkspace) or you can explicitly designate an area in a form where the SmartPart will appear at runtime by using a SmartPartPlaceHolder control. The SmartPartPlaceHolder placeholder control has the SmartPartName property that automatically displays a SmartPart with that name if it is found within the current WorkItem.

To display a SmartPart in a SmartPartPlaceholder:
CustomerSmartPart csp;
csp = myWorkItem.SmartParts.AddNew<CustomerSmartPart>("CustomerSP");

To display a SmartPart in a Workspace:
public class MyWorkItem : WorkItem
{
protected override void OnRunStarted()
{
base.OnRunStarted();
CustomerSmartPart csp = this.SmartParts.AddNew<CustomerSmartPart>();
Workspaces"tabbedArea".Show(csp);
}
}
Feb 3, 2006 at 9:40 AM
originally posted by: ChrisHolmes

Unfortunately I too am stumped on how to get this to work. That first code snippet - where do you put that?

-----------------------------------------------------
CustomerSmartPart csp;
csp = myWorkItem.SmartParts.AddNew<CustomerSmartPart>("CustomerSP");
-----------------------------------------------------
Feb 9, 2006 at 3:30 PM
originally posted by: mitchm101

I was having the same problem. I want to use a smartpartplaceholder on my main form instead on a workspace. The smarpart needs to be created before the form. So to get this to work, create the form with a smartpartplaceholder, give the place holder a smartpartname and your application class should look something like this

public class MyApplication : FormShellApplication<ShellWorkItem,ShellForm>
{
/// <summary>
/// The main entry point for the application.
/// </summary>
STAThread
static void Main()
{
new MyApplication().Run();
}

protected override void BeforeShellCreated()
{
base.BeforeShellCreated();

this.RootWorkItem.SmartParts.AddNew<CustomerSmartPart>("CustomerSP");
}


}

The BeforeShellCreated() method will create your smart part before it creates the main form