Autor Beitrag
coolace
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 141



BeitragVerfasst: Do 05.01.12 02:07 
Hallo Leute,

ich googele und debugge und teste wir irre aber ich finde keine passende Lösung für mein Problem.

Ich will mir privat ein kleines prog. bauen das aus einem Ordner alle Bilder ausließt,danach
gebe ich mehrere neue Dateinamen ein und laße eine neue Form erscheinen in der oben die Picture Box
mit dem Bild drin ist und unten eine combobox mit den Namen. Alles steckt in 2 mehrdimensionalen Arrays.

Mein Problem, ich finde keine Möglichkeit eine Verbindung zwischen Bild und Text zu bekommen, sprich
wenn sich der Name der Textbox verändert soll er das Array durchlaufen und das passende Bild was angezeigt
wird finden, wie mach ich das?

LG

Coolace
dark-destination1988
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 178
Erhaltene Danke: 21



BeitragVerfasst: Do 05.01.12 08:58 
Also generell mal zu Linq.
Du hast unter umständen ein(e) Array/Liste mit den Namen der Bilder.
Theoretisch kannst du dir eine Klasse bauen mit Bildname und dem Bild.
Diese schmeisst du in eine Liste.

Jetzt kannst du die Suche wie folgt gestalten

ausblenden C#-Quelltext
1:
var bilder=(from b in bildern where b.name==[SUCHNAME_AUS_TEXTBOX] select b).ToList();					


diese abfrage gibt eine Liste von Bildern zurück, da es ja auch mehrere Suchergebnisse geben kann.

Zur Anzeige dieses bildes könntest du anschliessend entweder das erste bild anzeigen lassen, oder eventuell alle dynamisch.

das erste bild erhälst du beispielsweise wie folgt

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
if(bilder.Count>0)
{
    .... = bilder[0].Image
}
else
{
     MessageBox.Show("Kein Bild gefunden!");
}


Image ist dabei eine Property der obengenannten Klasse.
coolace Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 141



BeitragVerfasst: Do 05.01.12 17:33 
Hallo dark-destination1988,

danke für deine Antwort mein Problem ist aber ein bissel anders und liegt
unter Umständen an der Beschreibung von mir.

Ich lade eine neue Form die beinhaltet 6 pictureboxes und 6 comboboxes drunter,
in den comboboxen sind die Dateinamen drin die ich jedem Bild einzeln zuordnen kann.
Wenn dies erledigt ist kann ich mit weiterschalten die nächsten Bilder da reinladen und
wieder zuordnen.

Mein Problem: Wie kann ich dafür sorgen das jedes Bild den richtigen Dateinamen bekommt,
hab es mit LINQ versucht aber nicht so wirklich hinbekommen.

Gruß

coolace
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4798
Erhaltene Danke: 1059

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Do 05.01.12 20:45 
Hallo coolace,

könntest du mal ein bißchen Code posten, denn aus deiner Beschreibung wird man (bzw. ich) nicht schlau?
coolace Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 141



BeitragVerfasst: Fr 06.01.12 13:38 
Hy,

das ist der momentane Code.

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:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
        string[,] namenauswahl;
        FileInfo[] originalnamen;
        string quelle;
        int counter=6;
        string[,,] bilderarryzuordung;
        Int32 arraygroeße; 

        public Bildauswahl(string name, string[,] bildernamenarry, string Pfadangabe)
        {
            InitializeComponent();           
            arraygroeße = bildernamenarry.Length/2;
            //Hier werden die ganzen Namen für die Zuordnung geteilt
            string[] tempumwandler = name.Split(';');
            namenauswahl = new string[tempumwandler.Length, tempumwandler.Length];
            for (int l = 0; l < tempumwandler.Length; l++)
      {
                
                namenauswahl[l, 0] = tempumwandler[l];
                namenauswahl[l, 1] = Convert.ToString(l+1);
                comboBox1.Items.Add(l+1);
                comboBox2.Items.Add(l+1);
                comboBox3.Items.Add(l+1);
                comboBox4.Items.Add(l + 1);
                comboBox5.Items.Add(l + 1);
                comboBox6.Items.Add(l + 1); 
      }  
            quelle = Pfadangabe;
          
            bilderarryzuordung = new string[arraygroeße, 13];      
            for (int i = 0; i < arraygroeße; i++)
      {
       bilderarryzuordung[i,0,0] = bildernamenarry[i,0];
             bilderarryzuordung[i,0,1] = bildernamenarry[i,1]; 
      } 
                    
            bildweiterschalter(0);
            comboBox1.SelectedIndex = 0;
            comboBox2.SelectedIndex = 0;
            comboBox3.SelectedIndex = 0;
            comboBox4.SelectedIndex = 0;
            comboBox5.SelectedIndex = 0;
            comboBox6.SelectedIndex = 0;
        }

        public void bildweiterschalter(int c)
        {
            try
            {
                for (int i = c; i < arraygroeße; i=i+5)
          {
                    if (Convert.ToInt32(bilderarryzuordung[i,0,1]) == i+1)
                    {
                        p1.Image = Image.FromFile(quelle + '\\' + bilderarryzuordung[i, 0,0].ToString()); 
                    }
                    if (Convert.ToInt32(bilderarryzuordung[i+1,0,1]) == i + 2)
                    {
                        p2.Image = Image.FromFile(quelle + '\\' + bilderarryzuordung[i + 10,0].ToString()); 
                    }
                    if (Convert.ToInt32(bilderarryzuordung[i+2,0,1]) == i +3)
                    {
                        p3.Image = Image.FromFile(quelle + '\\' + bilderarryzuordung[i + 20,0].ToString()); 
                    }
                    if (Convert.ToInt32(bilderarryzuordung[i+3,0,1]) == i + 4)
                    {
                        p4.Image = Image.FromFile(quelle + '\\' + bilderarryzuordung[i + 30,0].ToString()); 
                    }
                    if (Convert.ToInt32(bilderarryzuordung[i+4,0,1]) == i + 5)
                    {
                        p5.Image = Image.FromFile(quelle + '\\' + bilderarryzuordung[i + 40,0].ToString()); 
                    }
                    if (Convert.ToInt32(bilderarryzuordung[i+50,1]) == i + 6)
                    {
                        p6.Image = Image.FromFile(quelle + '\\' + bilderarryzuordung[i + 50,0].ToString()); 
                    }
                    //brauch ich da sonst immer alle durchläuft aber Nie die wo ich den Counter setze
                    break;
         }            
            }
            catch (Exception)
            {
            }            
        }          

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {            
            if (e.KeyCode == Keys.Up)
            {
                if (counter>=6)
                {
                    counter = counter - 6;
                    bildweiterschalter(counter);                  
                }               
            }   

            if (e.KeyCode == Keys.Down)
            {
                counter = counter + 6;
                bildweiterschalter(counter);
                
            }
            
        }

        private void comboBox1_TextChanged(object sender, EventArgs e)
        {        
           string[] dateiformat=  bilderarryzuordung[counter, 0,0].Split('.');
           if (comboBox1.SelectedItem != null && comboBox1.SelectedIndex > 0)
           {       
             bilderarryzuordung[counter-6,0,2] = namenauswahl[Convert.ToInt32(comboBox1.SelectedItem)-10].ToString() + "." + dateiformat[dateiformat.Length - 1];
           
           }
        
        }

        private void comboBox2_TextChanged(object sender, EventArgs e)
        {
            string[] dateiformat = bilderarryzuordung[counter, 0,0].Split('.');
            if (comboBox2.SelectedItem != null && comboBox2.SelectedIndex > 0)
         {
               bilderarryzuordung[counter-5,0,2] = namenauswahl[Convert.ToInt32(comboBox1.SelectedItem) - 10].ToString() + "." + dateiformat[dateiformat.Length - 1]; 
        }                      
        }

        private void comboBox3_TextChanged(object sender, EventArgs e)
        {
            string[] dateiformat = bilderarryzuordung[counter, 0,0].Split('.');
            if (comboBox3.SelectedItem != null && comboBox3.SelectedIndex > 0)
            {
                bilderarryzuordung[counter-40,2] = namenauswahl[Convert.ToInt32(comboBox1.SelectedItem) - 10].ToString() + "." + dateiformat[dateiformat.Length - 1];  
            }                       
        }

        private void comboBox4_TextChanged(object sender, EventArgs e)
        {
            string[] dateiformat = bilderarryzuordung[counter, 0,0].Split('.');
            if (comboBox4.SelectedItem != null && comboBox4.SelectedIndex > 0)
            {
                bilderarryzuordung[counter-30,2] = namenauswahl[Convert.ToInt32(comboBox1.SelectedItem) - 10].ToString() + "." + dateiformat[dateiformat.Length - 1];  
            }            
        }

        private void comboBox5_TextChanged(object sender, EventArgs e)
        {
            string[] dateiformat = bilderarryzuordung[counter, 0,0].Split('.');
            if (comboBox5.SelectedItem != null && comboBox5.SelectedIndex > 0)
            {
                bilderarryzuordung[counter-20,2] = namenauswahl[Convert.ToInt32(comboBox1.SelectedItem) - 10].ToString() + "." + dateiformat[dateiformat.Length - 1];                         
            }
        }

        private void comboBox6_TextChanged(object sender, EventArgs e)
        {
            string[] dateiformat = bilderarryzuordung[counter, 0,0].Split('.');
            if (comboBox6.SelectedItem != null && comboBox6.SelectedIndex > 0)
            {
                bilderarryzuordung[counter-10,2] = namenauswahl[Convert.ToInt32(comboBox1.SelectedItem) - 10].ToString() + "." + dateiformat[dateiformat.Length - 1];                         
            }
        }

        private void Bildauswahl_FormClosing(object sender, FormClosingEventArgs e)
        {
            ((Form1)Owner).Namensrueckgabe(bilderarryzuordung);
        }
    }
}


Gruß

Coolace

Moderiert von user profile iconTh69: Code- durch C#-Tags ersetzt