Autor Beitrag
Chiyoko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 298
Erhaltene Danke: 8

Win 98, Win Xp, Win 10
C# / C (VS 2019)
BeitragVerfasst: Di 02.08.11 09:00 
huhu,

Wie der Name schon sagt, stehe ich vor folgendem Problem:

Ich habe 10 PictureBoxen und 2 Buttons.
Bisher habe ich es hinbekommen, die 10 Bilder nach Auswahl des Ordners zu laden.
Die Frage ist dann, wie ich das Ganze organisiere, wenn es mehr als
10 Bilder und somit mehr als 10 Pictureboxen sind, ohne dass ich auch noch
weitere Pictureboxen anlegen muss.

Wie folgt, meine ersten Ansätze.Danke für jeden Tip.

Quellcode:
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
private int NumOfPicBoxen = 10;
private string OrdnerPfad;
List<string> Bildnamen = new List<string>();

private void AddPictureBoxen(int cNumber)
{
    picBoxArray = new PictureBox[cNumber];
    for (int i = 0; i < cNumber; i++)
    {
        picBoxArray[i] = new PictureBox();
    }
}

private void Form1_Load(object sender, EventArgs e)
{
    if (panel1 != null)
    {        
        AddPictureBoxen(NumOfPicBoxen);

        for (int i = 0; i < NumOfPicBoxen; i++)
        {
            picBoxArray[i].BackColor = Color.Transparent;
            picBoxArray[i].BorderStyle = BorderStyle.FixedSingle;
            picBoxArray[i].Size = new Size(198147);
            picBoxArray[i].Visible = true;
            picBoxArray[i].SizeMode = PictureBoxSizeMode.Zoom;
            picBoxArray[i].Name = i.ToString();
            picBoxArray[0].Location = new Point(7550);
            picBoxArray[1].Location = new Point(29350);
            picBoxArray[2].Location = new Point(51050);
            picBoxArray[3].Location = new Point(72850);
            picBoxArray[4].Location = new Point(75267);
            picBoxArray[5].Location = new Point(293267);
            picBoxArray[6].Location = new Point(510267);
            picBoxArray[7].Location = new Point(728267);
            picBoxArray[8].Location = new Point(293485);
            picBoxArray[9].Location = new Point(510485);
            picBoxArray[i].MouseClick  += new MouseEventHandler(picBox_MouseClick);

            this.panel1.Controls.Add(picBoxArray[i]);
            Application.DoEvents();
        }
    }
}


private void öffnenToolStripMenuItem1_Click(object sender, EventArgs e)
{
    FolderBrowserDialog openBrowserDialog = new FolderBrowserDialog();
    int fileCount = 0;
    int fileMax = 0;

    if (openBrowserDialog.ShowDialog() == DialogResult.OK)
    {
        OrdnerPfad = openBrowserDialog.SelectedPath;
        DirectoryInfo dir = new DirectoryInfo(OrdnerPfad);
        fileCount = Bildnamen.Count;

        if (dir.Exists)
        {
            FileInfo[] str_gif = dir.GetFiles("*.gif", SearchOption.AllDirectories);
            FileInfo[] str_jpg = dir.GetFiles("*.jpg", SearchOption.AllDirectories);
            FileInfo[] str_bmp = dir.GetFiles("*.gif", SearchOption.AllDirectories);
            FileInfo[] str_png = dir.GetFiles("*.png", SearchOption.AllDirectories);

            foreach (FileInfo gifBilder in str_gif)
            {
                if (gifBilder.Exists)
                    Bildnamen.Add(gifBilder.FullName);
                else
                    return;
            }
            foreach (FileInfo jpgBilder in str_jpg)
            {
                if (jpgBilder.Exists)
                    Bildnamen.Add(jpgBilder.FullName);
                else
                    return;
            } 
            foreach (FileInfo bmpBilder in str_bmp)
            {
                if (bmpBilder.Exists)
                    Bildnamen.Add(bmpBilder.FullName);
                else
                    return;
            } 
            foreach (FileInfo pngBilder in str_png)
            {
                if (pngBilder.Exists)
                    Bildnamen.Add(pngBilder.FullName);
                else
                    return;
            }

            foreach (string str in Bildnamen)
            {
                if (str.Length > 0 && str.Length <=10)
                {
                    picBoxArray[fileMax].ImageLocation = str;
                    fileCount++;
                    fileMax++;
                }
                else
                    MessageBox.Show("In diesem Ordner befinden sich keine Bilder.\nFormate: jpg,gif,png,bmp");
            }
        }
    }
}

private void btn_vor_Click(object sender, EventArgs e)
{
    if (picBoxArray != null)
    {
        if (Bildnamen.Count <= 10 && Bildnamen.Count > 0return;
        if (Bildnamen.Count == 0return;

        if (Bildnamen.Count > 10 && Bildnamen.Count <= 20)
        { 
                    
        }
    }
}
dark-destination1988
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 178
Erhaltene Danke: 21



BeitragVerfasst: Di 02.08.11 09:20 
Brauchst du den unbedingt 10 pictureboxen?
also zur gleichen zeit alle bilder angezeit?
ich bin eher für listen als für arrays
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
List<PictureBox> pbList=new List<PictureBox>()
for(int i=0;i<picboxcount;i++)
{
PictureBox neu=new PictureBox();
pbList.Add(neu);
}
zuweisung dann
foreach(PictureBox pb in pbList)
{
pb.BackColor=....;
}
Chiyoko Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 298
Erhaltene Danke: 8

Win 98, Win Xp, Win 10
C# / C (VS 2019)
BeitragVerfasst: Di 02.08.11 10:07 
Ja, die 10 Bildboxen sollten schon statisch sein.
natürlich könnte ich auch wie du geschrieben hast,
alles von der Anzahl abhängig machen, aber das finde ich
persönlich etwas komisch, zumal ich dann auch immer berechnen
müsste, wie groß sie sein sollen.

Eine weitere Idee wäre vielleicht, ein 2tes panel zu erstellen und
dann damit jeweils hin und her zu switchen.Das wäre vielleicht auch
das einfachste,...
ja ich denke, ich bleib dabei.
jetzt gilt es nur noch heraus zu finden, wie ich, wenn schon Bilder
geladen worden sind, weitere hinzufüge, wird aber weniger ein problem denk ich.

Danke für deine Antwort.