0

有没有办法让消息框关闭并返回表单而不通过电子邮件发送数据?

中途 atm 只需要第二个 if/else if 语句的帮助。我对这一切都很陌生。

我的代码如下:)

//Button
    private void submitButton_Click(object sender, EventArgs e)
    {
        string software = null;
        string hardware = null;



        foreach (string s in softwareNeededCheckedListBox.CheckedItems)
        {
            software = software + '\n' + s;
        }

        foreach (string s in hardwareNeededCheckedListBox.CheckedItems)
        {
            hardware = hardware + '\n' + s;
        }

        if (yesRadioButton.Checked == true)
        {
           yesRadioButton.Text = "Yes";
            noRadioButton.Text = " ";
        }


        if (noRadioButton.Checked == true)
        {
           noRadioButton.Text = "No";
            yesRadioButton.Text = " ";
        }



        if (MessageBox.Show("First name: " + firstNameTextBox.Text + "  " + "Last name: " + lastNameTextBox.Text + "\n" + "\n" +
               "Will be working in " + areaOfTheCompanyComboBox.SelectedItem + "\n" + "\n" +
               "They will need the following software:" + software + "\n" + "\n" +
               "They will need the following hardware:" + hardware + "\n" + "\n" +
               "They will be seated: " + seatingLocationRichTextBox.Text + "\n" + "\n" +
               "Any further Comments: " + notesRichTextBox.Text + "\n" + "\n" +
               "Do they require a phone: " + noRadioButton.Text + yesRadioButton.Text + "\n" + "\n" +
               "Date they start: " + completionDateTimePicker.Text + "\n" + "\n" +
               "Are you happy with the information shown above?" + "\n" + "\n" +
               MessageBoxButtons.OKCancel) == DialogResult.OK)
        {
            MailMessage mail = new MailMessage();
            SmtpClient smtpserver = new SmtpClient("smtp.gmail.com");

            mail.From = new MailAddress("xxxxx@gmail.com");
            mail.To.Add("xxxxx@xxxxxx.co.uk");
            mail.Subject = "Test Mail";
            mail.Body = "First name: " + firstNameTextBox.Text + "  " + "Last name: " + lastNameTextBox.Text + "\n" + "\n" +
                 "Will be working in " + areaOfTheCompanyComboBox.SelectedItem + "\n" + "\n" +
                 "They will need the following software:" + software + "\n" + "\n" +
                 "They will need the following hardware:" + hardware + "\n" + "\n" +
                 "They will be seated: " + seatingLocationRichTextBox.Text + "\n" + "\n" +
                 "Any further Comments: " + notesRichTextBox.Text + "\n" + "\n" +
                 "Do they require a phone: " + noRadioButton.Text + yesRadioButton.Text + "\n" + "\n" +
                 "Date they start: " + completionDateTimePicker.Text;
            smtpserver.Port = 587;
            smtpserver.Credentials = new System.Net.NetworkCredential("**", "********");
            smtpserver.Send(mail);
            MessageBox.Show("Your Form has been sent ");

        }
4

2 回答 2

4

您实际上忘记了将逗号放在您的位置以MessageBox.Show获取正确的参数/参数。

        if (MessageBox.Show("Body of your message box",
                            "Title Of Your MessageBox",
                            MessageBoxButtons.OKCancel,
                            MessageBoxIcon.Information) == DialogResult.OK)
        {

        }
于 2013-06-18T11:37:01.497 回答
0

只有在用户单击时才会发送电子邮件OK。您可以使用处理取消按钮DialogResult.Cancel

我会亲自将 MessageBox 放在一个dialogResult变量中。例如:

var dialogResult = MessageBox.Show("FIrst name .... ");

然后您可以检查用户是否按下OKCancel

if (dialogResult == DialogResult.OK) {
    // Send the e-mail
} else if (dialogResult == DialogResult.Cancel) {
    // Do what you need to do / return to the form.
}

要显示消息框,OK and Cancel您需要:

MessageBox.Show(this, "Message", "Title", MessageBoxButtons.OKCancel);
于 2013-06-18T11:36:44.770 回答