In Flex there is the ViewStack component. Does C# have a similar control?
If so, which? If not, how do you create similar behavior?
问题:
回答1:
Yes, the TabControl component works this way. All you have to do is hide the tabs. 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. The tabs are still visible at design time, makes it easy to edit the pages. But hidden at runtime. Use the SelectedTab or SelectedIndex property to select the view.
using System;
using System.Windows.Forms;
class ViewStack : 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);
}
}
回答2:
No, there is no standard control that provides the same behaviour.
However to get similar behaviour I would simply create a new UserControl for each item in the view stack and add these to a parent form at the same location and with the same width/height.
Using a helper method it is then simple to hide all user controls, and then display the specific user control based on an input parameter.
The major benefit of UserControls is that you can use the designer to visually create each of the separate stack items. A possible drawback is that if you have many items in the stack, or each stack item is complex, memory usage may become quite large.
回答3:
I don't think it exists natively. You will probably have to play with the Visible property.