ich eine Liste _Buffer
in Form2 mit Daten aus Form3
, Form4
, Form5
, Form6
, Form7
und Form8
erstellen möchten. Ich habe es funktioniert aber nur aus 1 Formular, wenn ich versuche, andere Elemente aus einer anderen Liste in Form4
zum Beispiel hinzugefügt, während ich bereits hinzugefügt von Form3
... in Form2
wird mir nur die Elemente von Form4
ohne die Elemente von Form3
ich hinzugefügt vorher. Hier ist, wie ich es tun:vorbei Liste zwischen Formen und das Hinzufügen am Ende es
-Code für Form2
:
ListArticle _Buffer = new ListArticle();
public void SetData(ListArticle article)
{
_Buffer = article;
}
-Code für Form3
:
public ListArticle _articles = new ListArticle();
public ListArticle Articles
{
get
{
return _articles;
}
set
{
_articles = value;
}
}
foreach (Color color in dominantColours)
{
MessageBox.Show(closestColor2(clist, color));
tshirt_number++;
_articles.Clothes.Add("T-shirt " + tshirt_number.ToString());
_articles.Colors.Add(closestColor2(clist, color));
Console.WriteLine("K: {0} (#{1:x2}{2:x2}{3:x2})", color, color.R, color.G, color.B);
string hex = color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2");
}
Anmerkung: closestColor2
eine string
zurück;
und hier ist, wie ich sie in die Liste in Form2
hinzufügen:
Form2 frm = new Form2();
frm.Show();
Articles = _articles;
frm.SetData(Articles);
this.Hide();
Form4
Code ist sehr ähnlich dem Code von Form3 .. nur eine andere Liste. Hier
ist die ListArticle
Klasse:
public class ListArticle
{
public List<string> Clothes { get; private set; }
public List<string> Colors { get; private set; }
public ListArticle()
{
Clothes = new List<string>();
Colors = new List<string>();
}
}
Also im Grunde möchte ich Elemente, die ich in Form4
am Ende der Elemente in den füge ich in Form3
hinzuzufügen.
In 'Form3, Form4, form5 ...' Sie schaffen neue Instanz von 'Form2'? Wenn das so ist, ist das falsch.Sie benötigen eine Form2-Instanz, und alle anderen Formulare müssen auf die Artikelliste von Form2 zugreifen. – Reniuz
@Reniuz Ich mache so etwas: 'Form2 frm = new Form2(); frm.Show(); '. Wie mache ich eine 'Form2'-Instanz? –