Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 939
user1809095 Avatar asked Jan 15 '23 21:01

user1809095


2 Answers

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!

like image 73
Daniel Lane Avatar answered Jan 24 '23 13:01

Daniel Lane


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

like image 24
Gustav Klimt Avatar answered Jan 24 '23 14:01

Gustav Klimt