Try the following:
Create your user controls:
- Click "File"
- Select "New"
- Select "Project"
- Click "Visual C#"
- Select "Windows"
- Select "Windows Forms Control Library"
- Change "Name" as desired (ex: "MyUserControls"
- Click "OK"
Add second UserControl:
- Click "Project"
- Select "Add New Item"
- Select "User Control"
- Click "Add"
When following the tutorial
How to pass data between two forms in C#
do the following:
In "UserControl1.cs":
- Add "ScheduleInfo.cs" code
- Add "ValueUpdatedEventArgs.cs" code
- Add "ChildFrm.cs" code to "UserControl1.cs"
- Add any desired controls to "UserControl1"
UserControl2:
- Add label named "label1"
In "UserControl2.cs" add the following code:
public void SetLabel1Text(string userValue)
{
this.label1.Text = userValue;
}//SetLabel1Text
Build Windows Forms Control Library project (ex: "MyUserControls")
- Click "Build"
- Click "Build MyUserControls"
Create a Windows Forms Application project:
- Click "File"
- Select "New"
- Select "Project"
- Click "Visual C#"
- Select "Windows"
- Select "Windows Forms Application"
- Change "Name" as desired (ex: "UserControlPassData")
- Click "OK"
If desired, add second form:
- Click "Project"
- Select "Add New Item"
- Select "Windows Form"
- Click "Add"
Add user controls to Toolbox:
- Click "View"
- Click "ToolBox"
- Right-click in ToolBox
- Select "Choose Items..."
- Click ".NET Framework Components"
- Click "Browse" button
- Choose your Windows Forms Control Library dll (ex: "MyUserControls.dll")
- Click "Open"
- Click "OK"
Add "UserControl1" to "Form1"
- Click "View"
- Click "ToolBox"
- Click "UserControl1"
- Click on "Form1" (to add control to Form1)
Add "UserControl2" using the same process as used to add "UserControl1".
Note: If adding UserControl2 to "Form2", then right-click on "UserControl2" and select "Properties". Change "Modifiers" …