Autor Beitrag
Fakiz
Hält's aus hier
Beiträge: 12

Win Vista
Visual C# 2010, Visual Basic 2010
BeitragVerfasst: So 24.04.11 11:17 
Hallo,

und schon wieder stecke ich fest. Ich versuche jetzt schon einige Stunden eine If - Anweisung zum laufen zu bringen aber es gelingt mir leider nicht. Das Problem ist ich will das eine MessageBox ausgegeben wird wenn ein leer - String zurückgegeben wird und genau hier liegt mein Problem, die MessageBox wird mir nicht ausgegeben. Vieleicht könnte sich jemand einmal meinen Code ansehen.

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
        private void button2_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if (openFileDialog1.FileName == "")
                    MessageBox.Show("Nichts gewählt");
                else
                    this.ShowIcon = true;
                    this.Icon = new Icon(openFileDialog1.FileName);
            }
            else
                this.ShowIcon = false;
        }
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: So 24.04.11 11:34 
Hallo,

der OpenFileDialog erlaubt ja gar nicht die leere Auswahl (d.h. bei 'Öffnen' bleibt der Dialog dann ja trotzdem weiter offen) und daher kann dein Fall also niemals eintreten. ;-)
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 24.04.11 11:40 
Außerdem fehlen dir Klammern bei deinem else, sonst passt das nicht zu deiner Einrückung. ;-)

Was du meintest ist wohl das:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
        private void button2_Click(object sender, EventArgs e)
        {
            this.ShowIcon = openFileDialog1.ShowDialog() == DialogResult.OK;
            if (this.ShowIcon)
                this.Icon = new Icon(openFileDialog1.FileName);
            else
                MessageBox.Show("Nichts gewählt");
        }