Setting ToolWindow width programatically

Docking/MDI for Windows Forms Forum

Posted 19 years ago by Crispin Horsfield - Software developer, Caz Limited
Avatar
I'm sure this should be easy...

At runtime I want to set the width of a ToolWindow to correspond to the design-time width of a UserControl ie when the ToolWindow is created anew, the width of the ToolWindow that contains the control is assigned a particular value. That way the user gets to see the whole control by default - whether they chose to hide a bit of it later is up to them.

This code isn't working as intended:

Dim objChildControl As New MyUserControl()

_twToolWindow = New ToolWindow(ctlDockManager, "MyUserControl", "My User Control", -1, objChildControl)

With _twToolWindow 
    .DockTo(ctlDockManager, DockOperationType.LeftOuter)
    .Width = 350
End With

I've tried various combinations to no avail and it's not appropriate (in this instance) to save the whole layout. This ToolWindow will only be used once in a while, so I destroy it before saving the layout of the other ToolWindows on application close.

Any help would be appreciated.

Crispin

Comments (7)

Posted 19 years ago by Boyd - Sr. Software Developer, Patterson Consulting, LLC
Avatar
Instead of the 'Width' property, use the 'DockedSize' and 'FloatingSize' properties to adjust the size of the ToolWindow. That should do the trick.
Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I don't believe setting DockedSize will adjust a tool window that is already docked yet. However modifying FloatingSize does adjust an active floating tool window at run-time.

But setting of DockedSize before calling DockTo does tell the tool window to use the specified DockedSize as its preferred target size. So that will help.


Actipro Software Support

Posted 19 years ago by Crispin Horsfield - Software developer, Caz Limited
Avatar
DockedSize is the one. This code behaved properly:

With _twToolWindow
    .DockedSize = New Size(350, .DockedSize.Height)
    .DockTo(ctlDockManager, DockOperationType.LeftOuter)
End With
Incidentally you can't do:

    .DockedSize.Width = 350
so you have to create a Size object.

Thanks to all.

Crispin
Posted 18 years ago by Mike Travers
Avatar
I can't get a ToolWindow to draw at the size I request using the .DockedSize property and then calling the .DockTo Method...any tricks to make this work...???

this is what I am doing...

ToolWindow.DockedSize = new Size(300, 500);
ToolWindow.DockTo(DockManager, ActiproSoftware.UIStudio.Dock.DockOperationType.RightOuter);

Any help appreciated...
Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
It shoudl be working... for instance if I paste this in the sample DockForm constructor, I get the events tool window to show at 500 wide:
eventsToolWindow.DockedSize = new Size(500, 500); 
eventsToolWindow.DockTo(dockManager, ActiproSoftware.UIStudio.Dock.DockOperationType.RightOuter);
Remember that when docking on the left/right, only the Width of the DockedSize is looked at. And when docking on the top/bottom, only the Height of the DockedSize is looked at.


Actipro Software Support

Posted 18 years ago by Mike Travers
Avatar
Yep I agree…have tried that (what you suggested) and it does work in the example you quote.

Alas…

However, the issue I am having (which I can’t get to work) is when a ToolWindow is created outside the designer (or “InitializeComponent” code) - sizing just does not seem to work, i.e., using the overloaded constructor…

new ActiproSoftware.UIStudio.Dock.ToolWindow(DockManager, Key, Title, -1, Control);

followed by setting the DockedSize property to the required dimensions, as opposed to what goes on when the ToolWindow is created in the designer (the example you describe) using the…

new ActiproSoftware.UIStudio.Dock.ToolWindow()constructor (the ActiproSoftware.UIStudio.Dock.ToolWindowContainer is also created n the generated code as well).

When the ToolWindow is created programatically (using the parameterized constructor, first example above), and not in the designer generated code, setting the .DockedSize just does not seem to work…All ToolWindows (sometimes the first one does get it right…but from what I have seen only when docked outer right…!!! And then subsequent creations just don’t work in relation to sizing) – they seem to be created either 200 wide or 200 high, dependeing on their orientation/dock position - left/right 200 wide, top/bottom 200 high.


Your help would be greatly appreciated…
Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
The constructor won't make a difference. I believe the problem here is that you might be creating the tool windows in the constructor of the Form which is before the Form is created and sized. It works with designed windows because they do some delayed settings for those.

But try this out instead. This works fine for me if you place the code in Form.Load:
protected override void OnLoad(EventArgs e) {
    base.OnLoad(e);

    ToolWindow t = new ToolWindow(dockManager, "TEST", "TEST", -1, null);
    t.DockedSize = new Size(400, 400);
    t.DockTo(dockManager, DockOperationType.TopInner);
}


Actipro Software Support

The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.