Add a UserControl

You can use the UserControl to create a reusable control for your Wisej.NET application. In our case, we want to be able to navigate between pages of an application. On each page, we want the same navigation menu. So it makes sense to use a UserControl because it can be reused on each page.

To create a UserControl:

In the Solution Explorer, right-click and choose Add->New Item

From the menu that pops up, choose "Wisej.NET 4" and then "User Control". (Alternatively choose Wisej.NET 3 if you are using Wisej.NET 3)

Name your UserControl (Ie "Nagivation.cs") and click "Add"

Add some controls from the toolbox- in our case, we added a combobox and a label. Add some items to the combobox- ie "Page1", "Page2", "Page3".

Make sure that you have several pages in your application. You can add new pages by right-clicking on the project in the Solution Explorer and choosing Add -> New Item

Attach to the SelectedIndexChanged event of the combobox and add the following code to navigate between pages:

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
	switch (comboBox1.SelectedItem)
	{
		case "Page1":
			new Page1().Show();
			break;
		case "Page2":
			new Page2().Show();
			break;
		case "Page3":
			new Page3().Show();
			break;
		default:
			new Page1().Show();
			break;
	}
}

Compile the project. Open the designer and you will now see the usercontrol. Click and drag it into the page. Repeat this for each page in the application.

Last updated

Was this helpful?