问题
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