以下自定义消息框的

以下自定义消息框的

本文介绍了以下自定义消息框的“自定义对话框"结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为以下代码实现自定义对话框结果,为获得对话框结果我需要在以下代码中进行哪些更改?

How can I implement custom dialog result for the following code, what all the changes I need to make in the following code to get the dialog result?

private void addButton(enumMessageButton MessageButton)
    {
        switch (MessageButton)
        {
            case enumMessageButton.OK:
                {
                    //If type of enumButton is OK then we add OK button only.
                    Button btnOk = new Button();  //Create object of Button.
                    btnOk.Text = "OK";  //Here we set text of Button.
                    btnOk.DialogResult = DialogResult.OK;  //Set DialogResult property of button.
                    btnOk.FlatStyle = FlatStyle.Popup;  //Set flat appearence of button.
                    btnOk.FlatAppearance.BorderSize = 0;
                    btnOk.SetBounds(pnlShowMessage.ClientSize.Width - 80, 5, 75, 25);  // Set bounds of button.
                    pnlShowMessage.Controls.Add(btnOk);  //Finally Add button control on panel.
                }
                break;
            case enumMessageButton.OKCancel:
                {
                    Button btnOk = new Button();
                    btnOk.Text = "OK";
                    btnOk.DialogResult = DialogResult.OK;
                    btnOk.FlatStyle = FlatStyle.Popup;
                    btnOk.FlatAppearance.BorderSize = 0;
                    btnOk.SetBounds((pnlShowMessage.ClientSize.Width - 70), 5, 65, 25);
                    pnlShowMessage.Controls.Add(btnOk);

                    Button btnCancel = new Button();
                    btnCancel.Text = "Cancel";
                    btnCancel.DialogResult = DialogResult.Cancel;
                    btnCancel.FlatStyle = FlatStyle.Popup;
                    btnCancel.FlatAppearance.BorderSize = 0;
                    btnCancel.SetBounds((pnlShowMessage.ClientSize.Width - (btnOk.ClientSize.Width + 5 + 80)), 5, 75, 25);
                    pnlShowMessage.Controls.Add(btnCancel);

                }
                break;
        }
    }

internal static void ShowBox(string messageText, string messageTitle, enumMessageIcon messageIcon, enumMessageButton messageButton)
    {
        frmShowMessage frmMessage = new frmShowMessage();
        frmMessage.setMessage(messageText);
        frmMessage.Text = messageTitle;
        frmMessage.addIconImage(messageIcon);
        frmMessage.addButton(messageButton);
        frmMessage.ShowDialog();
    }

Main.cs

frmShowMessage.ShowBox("This is message box which represent message with title, custome button and custom icon.", "This is message title", enumMessageIcon.Question, enumMessageButton.OKCancel);

现在我该如何进一步实现代码以获取对话框结果?

Now how do further I implement code to get dialog result?

推荐答案

代替

internal static void ShowBox(string messageText, string messageTitle, enumMessageIcon messageIcon, enumMessageButton messageButton)
{
    frmShowMessage frmMessage = new frmShowMessage();
    frmMessage.setMessage(messageText);
    frmMessage.Text = messageTitle;
    frmMessage.addIconImage(messageIcon);
    frmMessage.addButton(messageButton);
    frmMessage.ShowDialog();
}

尝试

internal static DialogResult ShowBox(string messageText, string messageTitle, enumMessageIcon messageIcon, enumMessageButton messageButton)
{
    frmShowMessage frmMessage = new frmShowMessage();
    frmMessage.setMessage(messageText);
    frmMessage.Text = messageTitle;
    frmMessage.addIconImage(messageIcon);
    frmMessage.addButton(messageButton);
    return frmMessage.ShowDialog();
}

这篇关于以下自定义消息框的“自定义对话框"结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 05:01