To the extent your goal is not, imho, fully revealed, I am going to show some code that reflects some arbitrary decisions ... in the hope you;ll find the strategy and methods useful :)
I suggest you use a kind of model-view design:
using System.Collections.Generic;
using System.Drawing;
namespace YourNameSpace
{
public static class Model
{
public static Dictionary<UCPlayerAccount, PersonModel> PAcctToPModel =
new Dictionary<UCPlayerAccount, PersonModel>();
}
public class PersonModel
{
public PersonModel()
{
}
public PersonModel(int id, string firstName, string lastName, string nickName, int points, int currLevel,
int currClass, List<Image> avatars)
{
Id = id;
FirstName = firstName;
LastName = lastName;
NickName = nickName;
Points = points;
CurrLevel = currLevel;
CurrClass = currClass;
Avatars = avatars;
}
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string NickName { get; set; }
public int Points { get; set; }
public int CurrLevel { get; set; }
public int CurrClass { get; set; }
public List<Image> Avatars { get; set; } = new List<Image>();
public string FullName => $"{FirstName} {LastName}";
}
}
The static Model class maps each instance of the UCPlayerAccount to an instance of the PersonModel Class: the Dictionary values are entered when the UCPlayerAccount is initialized(in the Load Event):
using System;
using System.Drawing;
using System.Windows.Forms;
namespace YourNameSpace
{
public partial class UCPlayerAccount : UserControl
{
public UCPlayerAccount()
{
InitializeComponent();
}
public PersonModel PModel { set; get; } = new PersonModel();
private void UCPlayerAccount_Load(object sender, EventArgs e)
{
Model.PAcctToPModel.Add(this, PModel);
}
private void btnOpenUCX_Click(object sender, EventArgs e)
{
UCX ucx = new UCX(PModel);
this.Controls.Add(ucx);
ucx.Location = new Point(20,100);
}
}
}
I am not sure where you wish the UCX to be placed, so I show it here being created, placed, inside the UCPlayerAccount:
using System
using System.Windows.Forms;
namespace YourNameSpace
{
public partial class UCX : UserControl
{
public UCX()
{
InitializeComponent();
}
public UCX(PersonModel pmodel)
{
InitializeComponent();
PModel = pmodel;
}
private PersonModel PModel;
private void btnWhatever_Click(object sender, EventArgs e)
{
if (PModel != null) PModel.Points = 100;
}
}
}
Demonstrates how the PersonModel associated with the UCPlayerAccount can be accessed from the UCX.
Since the instance of the UCX is created in the scope of a method in the UCPlayerAccount ... no reference is kept "alive:" ... imho, that is consistent with separation of concerns,
Keeping data models outside Views/Controls pays off, imho, in many ways: for example, the static class 'Model could have a collection of PersonModel that could be serialized, de-serialized, using standard methods.