gpt4 book ai didi

c# - 自定义 MessageBox DialogResult

转载 作者:行者123 更新时间:2023-12-03 07:53:38 24 4
gpt4 key购买 nike

我还有一个带有自定义按钮的自定义 c# MessageBox,并且我覆盖了 Show() 方法,这是我的大部分代码:

public partial class CustomMessageBox : Form
{
public CustomMessageBox()
{
InitializeComponent();
}
#region Variables
public static CustomMessageBox MsgBox;
public static DialogResult result;
public enum CustomMessageBoxButtons { Ok, OkCancel }
public enum CustomMessageBoxTxtBoxState { VisibleChar, PasswordChar, VisibleCharReadOnly }
#endregion

public static DialogResult Show(string text, string title, CustomMessageBoxButtons buttons)
{
MsgBox = new CustomMessageBox();
MsgBox.txtbox_content.Text = text;
MsgBox.lbl_Title.Text = title;
result = DialogResult.No;
if (buttons == CustomMessageBoxButtons.Ok)
{
MsgBox.btn_ok.Location = new Point(86, 70);
MsgBox.btn_cancel.Visible = false;
}
MsgBox.ShowDialog();
return result;
}

这里是自定义按钮的事件
private void btn_ok_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
}

private void btn_cancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
}
private void btn_close_Click(object sender, EventArgs e)
{
this.Close();
}

问题就在这里
private void flatButton1_Click(object sender, EventArgs e)
{
if (CustomMessageBox.Show("Title", "TITLEEE", CustomMessageBox.CustomMessageBoxButtons.OkCancel) ==**CustomMessageBox.MsgBox.result.Yes**)
{
CustomMessageBox.Show("Aceptaste", "AGREED", CustomMessageBox.CustomMessageBoxButtons.Ok);
}
else
{
CustomMessageBox.Show("Rechazaste", "dENIED", CustomMessageBox.CustomMessageBoxButtons.Ok);
}
}
#endregion

当我调用我的 messageBox 时,它会在 CustomMessageBox.MsgBox.result.Yes 上给我一个错误。说

Cannot be accessed with a WinForms instance Reference, QualifyIt with a type Name Instead



所以我该怎么办?

最佳答案

您没有将 Show 方法的结果与 DialogResult 进行比较。

而不是使用

if (CustomMessageBox.Show("Title", "TITLEEE", CustomMessageBox.CustomMessageBoxButtons.OkCancel) == CustomMessageBox.MsgBox.result.Yes)

尝试使用
if (CustomMessageBox.Show("Title", "TITLEEE", CustomMessageBox.CustomMessageBoxButtons.OkCancel) == DialogResult.Yes)

关于c# - 自定义 MessageBox DialogResult,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40836794/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com