user1809095
user1809095

Reputation: 411

C# Multiple Screen View Single Form

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

Upvotes: 4

Views: 7005

Answers (3)

Daniel Lane
Daniel Lane

Reputation: 2593

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!

Upvotes: 7

Ravi Y
Ravi Y

Reputation: 4376

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

Upvotes: 1

Gustav Klimt
Gustav Klimt

Reputation: 440

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

Upvotes: 1

Related Questions