Introduction
This tip provides an example in which the content area of a single document interface application is switched between two or more UserControl
s.
Background
This tip was created in response to a question in Quick Answers.
Using the code
The code contains a parent Form
, containing a ToolStripContainer
. The tool strip contains two buttons, used to switch between user controls. The user controls are added/removed to the container's Content
property in response to button presses.
using System.Windows.Forms;
namespace RedCell.App.Example.UserControls
{
public partial class MainForm : Form
{
private readonly UserControl _christmasCarolControl;
private readonly UserControl _greatExpectationsControl;
public MainForm()
{
InitializeComponent();
_christmasCarolControl = new ChristmasCarol {Dock = DockStyle.Fill};
_greatExpectationsControl = new GreatExpectations { Dock = DockStyle.Fill };
}
private void GreatExpectationsButton_Click(object sender, System.EventArgs e)
{
ToolStripContainer.ContentPanel.Controls.Clear();
ToolStripContainer.ContentPanel.Controls.Add(_greatExpectationsControl);
}
private void ChristmasCarolButton_Click(object sender, System.EventArgs e)
{
ToolStripContainer.ContentPanel.Controls.Clear();
ToolStripContainer.ContentPanel.Controls.Add(_christmasCarolControl);
}
}
}
Yvan Rodrigues has 30 years of experience in information systems and software development for the industry. He is Senior Concept Designer at
Robotic Assistance Devices
He is a Certified Technician (C.Tech.), a professional designation granted by the Institute of Engineering Technology of Ontario (IETO).
Yvan draws on experience as owner of
Red Cell Innovation Inc.,
Mabel's Labels Inc. as Manager of Systems and Development, the
University of Waterloo as Information Systems Manager, and
OTTO Motors as Senior Systems Engineer and Senior Concept Designer.
Yvan is currently focused on design of embedded systems.