C# Multiple Screen View Single Form

半世苍凉 提交于 2019-12-12 11:53:07

问题


I created a GUI in C# which should look like this:

On Main Screen there are two Buttons, When Button1 is clicked I don't want to open a new form using form2.show(); but while staying in the same form I want to change display.

I did this using hiding GUI elements and showing the other elements as required.

It works fine as I wanted but in the designer View of Form1 I had to create messy GUI.

My question is that is it good programming practice or not? If not then what is the best or recommended way to achieve this.

thanks


回答1:


You might want to consider a 'Tabless' tab control, I tend to use them for a lot of my work these days as it's easy and quick to build an interface using the win-forms designer with them.

    class TablessTabControl : 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);
        }
    }

This will extend the tab control and hide the tabs along the top, you can then change tab programmatically by using code similar to the following:

    tablessTabControl.SelectTab("tabName");

This isn't my original work, I found it floating around the web a while back and can't remember where I saw it. Anyway I hope this helps!




回答2:


how about using TabControl, you get all the 'views' you want without messy visible = true/false shizzle.




回答3:


You could create different child controls View1 and View2 and Show/hide each control based on the form state and the button clicks.



来源:https://stackoverflow.com/questions/13602824/c-sharp-multiple-screen-view-single-form

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