I have been using the window workspace quite a bit lately by passing in an owner form. The owner form is most of the time the shell form. So the first obvious thing I wanted was to have a form start position. So I wrote a unit test then added a FormStartPosition to the WindowSmartPartInfo.
[TestMethod]
public void FormSetsStartPosition()
{
TestableRootWorkItem workItem = new TestableRootWorkItem();
WindowWorkspace workspace = workItem.Workspaces.AddNew<WindowWorkspace>();
MockSmartPart smartPart = workItem.SmartParts.AddNew<MockSmartPart>();
WindowSmartPartInfo info = new WindowSmartPartInfo();
info.StartPosition = FormStartPosition.CenterParent;
workspace.Show(smartPart, info);
Assert.AreEqual(workspace.Windows[smartPart].StartPosition, FormStartPosition.CenterParent);
}
Added Code:
/// <summary>
/// Sets the location information for the given form.
/// </summary>
protected void SetWindowLocation(Form form, WindowSmartPartInfo info)
{
form.Location = info.Location;
form.StartPosition = info.StartPosition;
}
The test passed and it seemed to work fine until I really tried to use it in an app. When I checked the FormStartPosition of the new window it was correct but it still did not show in the right place. After furthur investigaton the issue was the location was always being set to 0,0. To fix this I initialized the location to Point.Empty in the WindowSmartPartInfo and added a check in SetWindowLocation.
/// <summary>
/// Sets the location information for the given form.
/// </summary>
protected void SetWindowLocation(Form form, WindowSmartPartInfo info)
{
if (info.Location != Point.Empty)
form.Location = info.Location;
form.StartPosition = info.StartPosition;
}
More to come on tweaking the window workspace