0

I´ve got the following code-line to show a Window in a MessageBox:

MessageBox.Show(new ElbaKostenstellen(titel, loginid).ShowDialog().ToString());

The problem is, that when I close it, another MessageBox starts with true or false, but I never told it to do. How can I fix that?

Here´s more relevant code:

                    string ganzes = sr.ReadToEnd();
                    string[] allezeilen = ganzes.Split('\n');

                    for (int i = 0; i < allezeilen.Length - 1; i++)
                    {
                        string[] separated = allezeilen[i].Split(';');

                        String datum = separated[0];
                        String titel = separated[1];
                        if (titel.Contains('"'))
                        {
                            titel = titel.Replace('"', ' ');
                        }
                        String betrag = separated[3];
                        buchrep.bookFromElbaCSV(datum, titel, betrag, loginid);
                        //ElbaKostenstellen ek = new ElbaKostenstellen(titel, loginid);
                        //ek.Show();
                       MessageBox.Show(new ElbaKostenstellen(titel, loginid).ShowDialog().ToString());
                    }
Dor Cohen
  • 16,769
  • 23
  • 93
  • 161
user896692
  • 2,351
  • 7
  • 36
  • 57

4 Answers4

4

In order to show a form calling ShowDialog on it is enough, a call to MessageBox.Show is unnecessary. Try;

new ElbaKostenstellen(titel, loginid).ShowDialog();

instead of

MessageBox.Show(new ElbaKostenstellen(titel, loginid).ShowDialog().ToString());
tafa
  • 7,146
  • 3
  • 36
  • 40
1

You told it when write this string

MessageBox.Show(new ElbaKostenstellen(titel, loginid).ShowDialog().ToString());

So you need to get message from ElbaKostenstellen without calling ShowDialog()

Likurg
  • 2,742
  • 17
  • 22
1

lets look at

MessageBox.Show(new ElbaKostenstellen(titel, loginid).ShowDialog().ToString()); 

The first bit that gets evaluated is

new ElbaKostenstellen(titel, loginid).ShowDialog()

this shows the dialog and the execution of code is blocked until the dialog is closed.

then the

MessageBox.Show(...)

is executed and displays the string representation of the result of the previous dialog.

I suspect you do not need the MessageBox.Show(..), just the new ElbaKostenstellen(titel, loginid).ShowDialog()

MaLio
  • 2,498
  • 16
  • 23
0

This is because the return value of ShowDialog is true or false.

As written here - http://msdn.microsoft.com/en-us/library/system.windows.window.showdialog.aspx

Return Value

Type: System.Nullable A Nullable value of type Boolean that specifies whether the activity was accepted (true) or canceled (false). The return value is the value of the DialogResult property before a window closes.

Dor Cohen
  • 16,769
  • 23
  • 93
  • 161