gpt4 book ai didi

c# - 使用委托(delegate)的可访问性不一致

转载 作者:太空宇宙 更新时间:2023-11-03 17:20:59 24 4
gpt4 key购买 nike

我正在尝试使用 Delegatestringform SettingsMenu 发送到我的主窗体,结构如下所示:

在 SettingsMenu 表单中委托(delegate):

delegate void ClocknameReceivedEventHandler(object sender, SettingsMenu.ClocknameReceivedEventArgs e);

SettingsMenu 类中的内部类 ClocknameReceivedEventArgs:

public partial class SettingsMenu : Form
{
internal class ClocknameReceivedEventArgs : EventArgs
{
string _clockname;
public string Clockname
{
get { return _clockname; }
}

public ClocknameReceivedEventArgs(string clockname)
{
_clockname = clockname;
}
}
}

SettingsMenu 中的更多代码:

public event ClocknameReceivedEventHandler ClocknameReceived;

// Invoke the Changed event; called whenever list changes
protected void OnClocknameReceived(SettingsMenu.ClocknameReceivedEventArgs e)
{
ClocknameReceived(this, e);
}

我使用以下 Event 在我的 Main form 上捕获来自 SettingsMenu 的传入数据:

_settings.ClocknameReceived += new ClocknameReceivedEventHandler(ClockClocknameReceived);

我的主窗体上实际从 SettingsMenu 接收字符串的方法:

private void ClockClocknameReceived(object sender, SettingsMenu.ClocknameReceivedEventArgs e)
{
string ClockName;
ClockName = e.Clockname;
lblClockname.Text = ClockName;
}

现在我在 SettingsMenu 类中得到以下错误:

Error   2   Inconsistent accessibility: parameter type 'LivePigeonClient.Forms.SettingsMenu.ClocknameReceivedEventArgs' is less accessible than method 'LivePigeonClient.Forms.SettingsMenu.OnClocknameReceived(LivePigeonClient.Forms.SettingsMenu.ClocknameReceivedEventArgs)'    D:\SVN\sentul\Livepigeonflights\trunk\LivePigeonClientSolution\LivePigeonClient\Forms\SettingsMenu.cs   54  24  LivePigeonClient

Error   1   Inconsistent accessibility: field type 'LivePigeonClient.Forms.ClocknameReceivedEventHandler' is less accessible than field 'LivePigeonClient.Forms.SettingsMenu.ClocknameReceived' D:\SVN\sentul\Livepigeonflights\trunk\LivePigeonClientSolution\LivePigeonClient\Forms\SettingsMenu.cs   51  52  LivePigeonClient

谁能告诉我我做错了什么?

最佳答案

我需要使用一个public delegate 和一个public class 来解决这个问题。

关于c# - 使用委托(delegate)的可访问性不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15427761/

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