WinForms Tab Control question

痞子三分冷 提交于 2019-12-03 08:47:52

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

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,

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!