温馨提示×

如何通过messagebox.show收集用户反馈

小樊
83
2024-07-01 15:40:40
栏目: 编程语言

您可以通过使用MessageBox.Show方法来向用户显示一个消息框,然后让用户输入反馈信息。以下是一个示例代码:

using System;
using System.Windows.Forms;

public class FeedbackForm : Form
{
    public FeedbackForm()
    {
        InitializeComponent();
    }

    private void InitializeComponent()
    {
        Button btnSubmit = new Button();
        btnSubmit.Text = "Submit Feedback";
        btnSubmit.Click += (sender, e) =>
        {
            string feedback = Microsoft.VisualBasic.Interaction.InputBox("Please enter your feedback:", "Feedback Form");
            if (!string.IsNullOrEmpty(feedback))
            {
                MessageBox.Show("Thank you for your feedback: " + feedback, "Feedback Submitted", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        };

        Controls.Add(btnSubmit);
    }
}

public class Program
{
    [STAThread]
    public static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new FeedbackForm());
    }
}

在上面的示例中,当用户单击"Submit Feedback"按钮时,会弹出一个输入框,用户可以在其中输入反馈信息。当用户点击OK按钮后,会显示一个消息框,显示用户输入的反馈信息。您可以根据您的需求对这段代码进行修改和扩展。

0