ToolWindows Disappear From Designer & Inherited ToolWindows

Docking/MDI for Windows Forms Forum

Posted 8 years ago by EntityDev
Version: 14.1.0323
Avatar

Hello,

ToolWindows disappear from the designer when hosting the DockManager in a derived UserControl. This is necessary (per the documentation) because I use the ToolStripContainer on my main form. This occurs when the main form's designer is visible while the solution is built. The designer code seems unaffected, as the ToolWindows reappear if the designer is closed and re-opened. I should add that I try not to do this in any case, particularly when a form is very busy. I'm sure we've all been bitten in the past. Occasionally I forget. So far, no harm done.

But I am concerned that my designer (generated) code might some day blow up. Yes it's in source code control, and I even keep static copies. I'm not overly concerned about it, but I'd be much obliged if you could comment on it.

Of somewhat more interest is my thought that it'd be nice if I could inherit from ToolWindow (I have), decorate it with a few controls such as a ToolStrip and a TreeView. 75% of my ToolWindows look like this. I'm wondering if I can use inherited ToolWindows, rather than adding them via the DockManager and decorating them in the main form designer. I believe it can be done, but I'm not sure how to introduce these objects to the DockManager. Is it possible to use only inherited (and fully decorated) ToolWindows without programmatically managing docking? I certainly don't want to reinvent your wheel.

But I'd very much like to keep as much clutter as possible out of the main form. In addition, I'd like to use inheritance to make my ToolWindow life a little easier.

Comments (10)

Posted 8 years ago by EntityDev
Avatar

I worked on this issue for 3 hours yesterday and 6 hours today. I feel I can safely state that this will not work, at least as I understand it. I re-read the relevant section in the documentation and found something that I'd overlooked before:

First the DockManager needs to be set to the interior of the ToolStripContainer. This is NOT to be done by setting the HostContainerControl property to the ToolStripContainer control itself.

It states how it is not done, but does not state how it IS done. I assumed that it means dragging a DockManager onto the ToolStripContainer.ContentPanel, rather than onto the component tray. I'm confused; the DockManager is a component and doesn't have a Location property, so cannot be set to the interior of anything, as far as I know.

In any case my main form has blown up a couple of times today, causing the loss of the DockManager and its host, and all ToolWindows. The requisite AutoHideContainers and AutoHideTabStripPanels were orphaned in the designer code.

But I'm not sure how I placed the DockManager onto the form. I may have dragged it onto the component tray. I have since recreated everything and dragged a DockManager onto the ToolStripContainer.ContentPanel. Then dropped a host control onto the same surface, Dock filled it and set it as the host of the DockManager. It seems better behaved, but I've only spent a couple minutes with it. I'll be testing further. One thing to note is that the BackColor I set for the host container control reverts to a light gray once it is set in the DockManager.

It'd be nice to get some feedback on this...

[Modified 8 years ago]

Posted 8 years ago by EntityDev
Avatar

After a bit of design work, the main form again lost the DockManager and the UserControl I was using as a host.

Posted 8 years ago by EntityDev
Avatar

Until I get a fix from support I have reverted to the ToolStripPanel, rather than the ToolStripContainer. I guess this is fine, but I don't have any experience with it. I need multiple ToolStrips but I keep the ToolStripContainer sides and bottom unused at any rate. I'm guessing ToolStripPanel provides what I need. I rather thought the ToolStripContainer replaced it.

Regarding backcolor - I found a forum post regarding the DockManager.DockRenderer.DockContainerBackgroundFill. I have set this to a particular color, but it has no effect whatsoever.

I must be able to set the background color of the main form, or whatever control on it which is visible to the user. When I inspect the form after it's configured with a DockContainer and set to TabbedMDI, the empty area of the Form appears to be the Form itself. Yet, setting its .BackColor also has no effect, when a DockManager is in play.

Please help.

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello, we're sorry to hear you're having trouble.

For the first question, I tried building an app with ToolStripContainer.  The ToolStripContainer is right in the main Form in my test project.  The documentation portion you quoted was only part of that topic since the subsequent paragraphs describe things more.  It's effectively saying that since DockManager.HostContainerControl requires a ContainerControl and the ToolStripContainer.ContentPanel is where the docking windows need to go but the ContentPanel is not a ContainerControl, you need to inject a ContainerControl in there that the DockManager can target as the HostContainerControl.  One way to do that is to use an empty UserControl instance, since UserControl inherits ContainerControl.  DockManager isn't a control itself.  It will inject its docking controls in whichever HostContainerControl you assign.

Can you verify if you have set things up the same?  I didn't see the controls disappear when leaving the Form designer open while running the app.

One thing you could do too is instead of having the DockManager on the Form and your empty UserControl used as the HostContainerControl, change things so that you open the designer for the UserControl itself and add the DockManager there.  Make the root UserControl (in its own designer) the HostContainerControl for its embedded DockManager.  Then back on the main Form, remove the DockManager there.  The UserControl instance that is child of the ToolWindowContainer.ContentPanel there will now have the docking windows inside of it, since the DockManager is inside of the designed UserControl contents.  That will help isolate the DockManager and its docking windows from the main Form and could help in case you have issues with the main Form.

For the second question, yes you should be able to make inherited tool windows.  I believe you can create a new UserControl and change it to inherit ToolWindow instead.  Then add this constructor in addtion to the default one too:

public MyToolWindow(DockManager dockManager, string key, string text, int imageIndex) : base(dockManager, key, text, imageIndex, null) {
	InitializeComponent();
}

You might have to create your tool window in code with that constructor and activate it programmatically, but the tool window's contents should be designable when it is open in the VS designer.  Once you have a layout you like for the tool windows in your app at run-time, save it to a layout file and use that as your default layout.  Note that you will need your tool windows intiially registered with the dock manager before loading a layout that references them since custom types are used.

For the back color of the Form, when you have a ToolStripContainer.ContentPanel, you need to select the ToolStripContainer in the property grid and select the ContentPanel.  Set its BackColor and that should show up in the main MDI-ish content area.

I hope all this helps!


Actipro Software Support

Posted 8 years ago by EntityDev
Avatar

Yes it helped, thanks very much. I can verify that I am set up as described, yes. I have emailed a simple project in which I've duplicated this setup. You should find that if you Rebuild the solution (not Build), while the main form designer is open, the UserControl and DockManager will disappear from the designer surface. This should also occur if you Debug/Run the project while the form designer is open, as a Rebuild also occurs when doing so.

For a time, closing the designer and reopening it takes care of the problem. Eventually, however, some little thing you do is going to blow it up and the missing controls will not be recoverable. It is some combination of Build, Rebuild, opening the form designer, etc. I haven't nailed it down to the precise order of events that blows it all up. I confess that I'd rather not.

What has helped is your suggestion that I try hosting the DockManager in the UserControl designer instead of the main Form. This seems to be stable so far. There is no code behind the UserControl for manipulating documents and tool windows and such (other than generated designer code) - it's all behind the main form.

Additionally, I have already experimented with deriving from ToolWindow and programmatically tossing it at the DockManager. The constructor you've described should be helpful as well, thanks for that. I am not yet saving or loading layouts, but I will soon enough. I think I have the hang of using derived ToolWindows.

Lastly, the color of the empty MDI container appears to be managed by the renderer. Setting the BackColor any of the underlying controls has no effect. I've tried them all, including the ToolStripContainerContentPanel. In the end I found that I must have first set a renderer on the DockManager, then change that renderer's TabbedMDIRootContainerBackgroundFill.Color property.

[Modified 8 years ago]

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Thank you for the sample.  I do see the docking controls disappear when you do Rebuild Solution.  In my sample that I made, that wasn't happening.  I also saw that if you close and reopen your Form without changing anything, everything is restored.  However if you change something on the Form while in that bad state and save it, the docking UI is lost.  I've just emailed a contact on the Visual Studio team to see if they can route us over to someone who can help explain why that's happening.  I'll give you an update once we get some info after working with them.

In the meantime, housing the DockManager in the UserControl designer seems like a good way to go.

Yes all rendering of the tabs and docking controls are done through renderers.  There are three renderers involved in docking windows, one for general docking controls, one for the tabbed MDI tab control, and one for the tool window tab control.


Actipro Software Support

Posted 8 years ago by EntityDev
Avatar

Thank you. If I decide to continue using ToolStripContainer, I'll employ the workaround where DockManager is hosted in a UserControl. I'll keep an eye out for any update. I'll take my renderer questions to another thread or communicate via email.

Posted 5 years ago by EntityDev
Avatar

After a long period doing other things, I am back now to building an MDI interface. I have downloaded the 2016.1 Docking library.

Was the above issue resolved?

Thanks

Posted 5 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

From the email conversation with Microsoft back in May 2016 on this issue, we had gone back and forth and they thought it might be a VS bug.  We had produced a repro scenario for them and created a Connect (their support system at the time) issue.  They said they were going to investigate it.  However since that time, they have disabled the Connect system and I'm no longer able to check status on the issue.  The answer to your question depends on if they ever did anything in newer builds of VS to resolve the problem.


Actipro Software Support

Posted 5 years ago by EntityDev
Avatar

Ok, thank you for the followup. My users never expressed interest in moving toolbars from the top of the form to any other position anyway, so I stopped using ToolStripContainer a while back.

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.