Reputation: 24679
I have a form that displays in two modes. Switching modes completely changes the appearance of the form much like you would expect if you were using a tab control and had a different layout of controls on each tab.
A tab control would be perfect if I could hide the tab itself.
Of course, I could use two panels and pro grammatically show and hide the appropriate panels. I tried this, but my anchoring keeps on getting messed up (I think it is a Visual Studio designer bug.)
Ideally, I'd like to use a "wizard" control, which is tab-less, and at designtime, draw the controls for the first page, switch the "PageNumber" property to page two, and then drop controls onto the second page.
I thought the TabControl had functionality to appear without tabs, which would lend itself nicely to creating a Wizard style interface, for example.
What's the best way to do this so that my design time appearance mimics the run-time?
At the moment, I have 2 panels, one directly over the other and I flip-flop the visible property of each and my auto anchoring is getting all messed up by VS. I may have to resort to writing my own archoring code, which isnt hard, but I like it when the design env reacts as closely as possibility to how the screen will look when it runs. It just makes life easier.
I have Telerik Q3 WinForm controls, too, in case there is an alternative in that control set...
Suggestions?
Upvotes: 3
Views: 3128
Reputation: 11104
To mimic hiding the Tab i just Remove
it. Problem is you can't get it back easily so I use it in forms where I know it will be opened for one particular reason and closed afterward without need to actually use the removed tab. If you open the Form again using different parameter it will open itself with other tab and delete the not needed ones.
Upvotes: 0
Reputation: 941455
It's possible. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form. It has tabs at design time so you can easily switch between pages. But hides them at runtime, use the SelectedIndex or SelectedTab property in your code to switch views.
using System;
using System.Windows.Forms;
class PageControl : TabControl {
protected override void WndProc(ref Message m) {
// Hide tabs by trapping the TCM_ADJUSTRECT message
if (m.Msg == 0x1328 && !DesignMode) m.Result = (IntPtr)1;
else base.WndProc(ref m);
}
}
Upvotes: 13
Reputation: 48139
I would definitely use custom "user control"s respective of each "content" you want to display, and as you stated, programmatically show / hide them. With respect to the "anchoring", Put stuff on the "user control" where you want and anchored respectively. Then, have your "user control" have its own anchor property for when you add it to your form. The resizing, anchor repositioning and re-drawing of controls only appears to be done when the control is visible. So, when you first start the form, make sure you make IT (user control) visible, THEN change its height/width as needed for its Initial display to the form, then run from there.
Upvotes: 0
Reputation: 10359
For what it's worth, I would suggest you a SplitContainer, and moving the SplitSeparator from left to right when needed ...
I'm not sure my answer will be of much value, but to think of it, this may be a convenient solution.
Hope this helps,
Upvotes: 0