简体   繁体   中英

C# Winform Question

I'm just getting started with winforms in C# and things are going well, except I want to learn how to do something like:

if user presses "proceed" button, it will run some code, and change the form, so that there are more options available to the user on the form. In other words, I want to make my forms more than one "page". I hope that all makes sense. Any help would be appreciated, thanks!

You could have a tab control with separate tabs that you move through that are disabled until they are needed. Each one could have its own controls, etc... You could have the controls disabled on the main form and then enable them, etc... There are myriad ways that you could approach this problem.

For winforms:

    private void button1_Click(object sender, EventArgs e)
    {
        textBox1.Visible = true;
    }

One easy way of doing that is to add a container control, for example a GroupBox that contains a selection of controls that belongs together and then you make that GroupBox invisible. Then in the button click handler you make it visible again.

That way all the related controls are shown/hidden together and if needed you can move them around the screen without needing to worry about their locations related to each other.

I want to make my forms more than one "page"

When I do that, I normally build each "page" as custom control. This let's me separate the navigation elements from what it is you're navigating to, so that I can easily play with different ideas later. For example, do I want to use a tab control to host each page inside a separate tab? No bid deal - just drop one my controls on each tab. Swap out different pages on the same form? It's only one control to replace. Move between completely different forms? Still easy.

As a basic starting point, if you want to run some code when the user clicks the button just handle the Click event. Just double click the button to get to the code-behind and place your code in there.

In terms of exposing extra functionality when the user clicks proceed there are various options available to you, its really up to you to figure out which is best suited to your application. One simple option would be to perhaps have a Panel or GroupBox and place all the extra options on there and make it disabled, then enable when you see fit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM