WindowWorkspace and View size

Topics: CAB & Smart Client Software Factory
Apr 17, 2007 at 5:10 PM
I'm experiencing a strange effect with repeatedly showing a view in a WindowWorkspace. The first time I show the View the WindowWorkspace (WW) is sized correctly to show the entire View. The next time I call Show() the WW defaults to a smaller size, maybe 200 x 200.

I'm not explicitly setting the size in the GetSmartPartInfo method because during initial testing it seemed to work fine autosizing, I've only recently discovered that after showing more than once it doesn't autosize correctly.

As a work around I added code in the GetSmartPartInfo method to set the size:
public ISmartPartInfo GetSmartPartInfo(Type smartPartInfoType)
{
    WindowSmartPartInfo wspi = new WindowSmartPartInfo();
    wspi.ControlBox = false;
    wspi.Icon       = System.Drawing.Icon.FromHandle( Resource.ModuleIcon.GetHicon() );
    wspi.Modal      = true;
    wspi.Title      = "Create new Build Order";
    wspi.Height     = this.Height;
    wspi.Width      = this.Width;
    wspi.Keys[WindowWorkspaceSetting.FormBorderStyle] = FormBorderStyle.FixedToolWindow;
    wspi.Keys[WindowWorkspaceSetting.StartPosition] = FormStartPosition.CenterParent;
 
    return wspi;
}

However this will slower shrink in Height after being called over and over. I think the problem is that the View is set to Dock.Fill and by setting the Form's Size = to the UserControl it's not taking into consideration the control bar.
Form.Size = UserControl.size causes UserControl to shrink to fit in the smaller space.

Before I go on hacking my way all over the place I thought I would check with you all to see if anyone else had come across this and if so, how you solved it. I would rather not add a static offset to compensate for the control bar as the size might change from machine to machine(?)

Thanks for any tips, I hope this all makes sense ;)

-Steve
Apr 25, 2007 at 3:48 PM
You're correct on both counts.

By setting Dock.Fill, you're running into a timing issue with the workspace, the control is added to the form before the workspace resizes the form to the control's size -- since the control fills when its added, its size is now the default size of the form.

We also ran into the shrinking size issue, which we found had to do with both client size of the form being different based on the options set, including the border style.

We resolved this by altering CAB/SCSF code -- we changed the workspace to automatically set the control's Dock to Fill, but only after the form had been created, the control was added to it, and the form resized.

We also added some features to the workspace, such as: remembering the size of form showing each view type based on the user's resizing action and managing the Window menu from the workspace (Close All and showing open documents in the menu).

I'm not in the office this week, so can't get at a code sample of what had to change for the resizing issue, but I'm pretty sure we added the Dock to the workspace's GetOrCreateForm() method.