Bonjour,
j'ai dans ce bout de code l'erreur suivante
A circular control reference has been made. A control cannot be owned by or parented to itself.
un singleton
1 2 3 4 5 6 7 8 9 10 11
| public static MyClass Instance
{
get
{
if (instance == null)
{
instance = new MyClass();
}
return instance;
}
} |
La méthode qui plante à l'intérieur de ma classe MyClass
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
public bool myMethod()
{
MyUserControl control = Instance
MainEditNewDialogGlobal dlg = new MainEditNewDialogGlobal(control);
DialogResult res = dlg.ShowDialog(this); ---> ERREUR ICI
if (res == DialogResult.OK)
{
return true;
}
return false;
} |
ma classe MainEditNewDialogGlobal
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
public partial class MainEditNewDialogGlobal : Form
{
private MainUserControl activeControl = null;
public MainEditNewDialogGlobal(MainUserControl control)
{
InitializeComponent();
this.ClientSize = control.Size;
this.Height += pnlButtons.Height;
this.activeControl = control;
this.activeControl.Parent = this;
this.activeControl.Dock = DockStyle.Fill;
this.activeControl.TabIndex = 1;
} |
L'erreur se produit quand je suis à la ligne
DialogResult res = dlg.ShowDialog(this);
et que ma propriété Instance ne vient pas d'être créée (depuis le 2ème appel).
Pourquoi est-ce que cela se produit? Quelle est la correction à apporter?
Tout fonctionne bien si je n'utilise pas un Singleton, mais justement l'idée est d'en utiliser un pour limiter le nombre d'instance de MyClass.
Quelqu'un aurait-il une idée ??
Merci d'avance amis développeurs.
Partager