abduls85
abduls85

Reputation: 548

C# need advice on a simple issue on form navigation

I need to simulate a form that is similar to the interface seen during installation of any software. There are next and back buttons and the all the information entered by the user is processed only when he/she clicks the finish button.
When the user clicks the back button, the previous entered information is showed to him/her.
When the user clicks the next button the next screen is show to him/her. All displayed information is shown in one form.

There are 3 section which I need to show the user.

Currently planning to implement the solution listed below :

  1. Create one form
  2. Add all the element for section 1 and create a next button event that will hide all the element shown in section 1 including the button and show all the elements section 2.
  3. Create button event for the back button for section 2 such that it hides all the elements in section 2 including the button and displays all the elements in section 1 and the next button to hide all the element in section 2 including the button and show all the element in section 3
  4. Create similar button event for section 3

Are there any better solution than the one describe above. If yes, please describe the approach. Any help provided will be greatly appreciated.

Upvotes: 6

Views: 488

Answers (5)

LoveMeSomeCode
LoveMeSomeCode

Reputation: 3937

Yeah, like iain said, the wizard control is probably your best bet, but if that doesn't work, try looking for MultiView or Accordian controls. They make controls that are specifically for hiding/showing sections on a form, so you don't have to go from form to form, and thus you stay in the same scope the whole time. Makes keeping the fields populated a lot easier.

Upvotes: 0

Matt F
Matt F

Reputation: 595

One way to achieve this is using a tab control and hiding the tabs so that the user can't navigate between them and instead you control moving from one tab to the next programatically.

I use the KryptonNavigator control as it provides many different modes that make it simple to hide tabs so that only tab content is visible, etc. However, it should be possible to hide the tabs of the standard tab control.

KryptonNavigator

Upvotes: 2

Kratz
Kratz

Reputation: 4330

You could create custom controls for the three different screens, then you could just add those 3 controls to the form, making it easier to hide/show the appropriate controls.

Or alternatively, you can create three separate forms, and then show your forms in order and perform the actions in the programs Main() function rather than using a form as your startup object. Like

static void Main()
{
  Form1 f1 = new Form1();
  if (f1.ShowDialog() == DialogResult.OK) 
  {
    // do actions
    // show next form
    // etc.
  }
}

Upvotes: 0

Caglar Gonul
Caglar Gonul

Reputation: 1

You can use usercontrol structure to achieve this kind of behaviour. You can add a simple panel control and change the content of the panel according to the buttons pressed. You can simply change the content of the panel by using yourPanel.Controls.Add(your_user_control). So different control sets can be implemented on a winform.

Thanks

Upvotes: 0

Related Questions