开发者

Does C# winforms has a control like "ViewStack" in Flex?

In Flex there i开发者_运维知识库s the ViewStack component. Does C# have a similar control?

If so, which? If not, how do you create similar behavior?


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);
  }
}


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.


I don't think it exists natively. You will probably have to play with the Visible property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜