0

We have some UserControls (that each have their own presenter). Each one lives within a TabPage on the main form.

One of them has a graphical display of objects you can interact with. When certain actions are taken we need to collect some information from the user, so we pop up a form (you could probably call it a dialog). We'd like this form to only be visible within that tab page, so you can flip to another tab to check some information and come back, etc.

We tried setting .TopLevel = false on the form, but that causes some weird behavior that's unacceptable. The various typical solutions to this (use MDI, no border on form, etc...) don't work in our circumstance.

Are there any other ways we can achieve the desired behavior?

Community
  • 1
  • 1
Jeff B
  • 8,572
  • 17
  • 61
  • 140
  • Quick answer is: not really. Best to document what goes wrong when you change the TopLevel to false. – LarsTech Jul 23 '13 at 20:13
  • 1
    Just don't display the form with a caption bar. It makes no sense to do this. It looks wrong and the user could move the form out of the tab page and not be able to get it back :) If you need a caption then just use a label. – Hans Passant Jul 24 '13 at 01:17

1 Answers1

2

Your question reminded me of a solution to a similar problem in WPF. Let me do my best to explain the problem and his solution.

The problem was to provide a method for the business logic to interact with the user through "Interaction Requests" that are then handled in the appropriate region of the user interface. The business logic would be unaware of the UI involved in the interaction, but would initiate the request event which was then handled be the UI. I couldn't find the example again and it was WPF centric anyway, but he basically he handled it by creating a control that mimic'd the look of a Modal Dialog. He then created an Action which handled the Interaction event and automatically inserted the Faux Dialog into the TabPage on top of the other controls in the TabPage. One trick was the Action assumed the Faux Dialog would be inserted into a Grid Control that was to be its parent.

So basically here's what I'm saying... as a possible solution

  1. Create a UserControl that looks just like a Modal Dialog. Except it is contained in a transparent region to fill its container.
  2. Have it be inserted into the TabPage's collection of Controls on top of all its other controls. Dock it to fill the TabPage.

Actually, here's some pictures..

Tab Page without dialog

And then when you add the user control.. You have a fake dialog which actually has a transparent area around it that fills the tab page..

Fake Dialog

The idea here is that you will not be able to interact with the controls below it, because it is on top, but it will still be inside the tab page, so that it doesn't affect interacting with the other tabs. The blue portion of the 2nd image should actually be transparent to give you the illusion that it doesn't exist, but prevent interacting with controls below it.

This has some limitations though because you cannot make your dialog larger than the tab page.

I guess maybe I'm suggesting you think "inside the box" ?

Alan
  • 7,875
  • 1
  • 28
  • 48
  • 1
    If I could give you an extra +1 for `I guess maybe I'm suggesting you think "inside the box"?` I would ;) – Jeff B Jul 24 '13 at 13:45