1

我正在尝试使用 a 将 a stringfrom发送form SettingsMenu到我的 Main 表单Delegate,结构如下所示:

以 SettingsMenu 形式代表:

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);
}

SettingsMenuMain form使用以下命令捕获来自我的传入数据Event

_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

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

4

4 回答 4

13

我需要使用 apublic delegate和 apublic class来解决问题。

于 2013-03-15T11:28:00.197 回答
2

您的事件参数被标记为内部,这意味着它不会在您的程序集之外共享:

internal class ClocknameReceivedEventArgs

但是然后你在一个被保护的方法上使用它(它在程序集之外可用):

protected void OnClocknameReceived(SettingsMenu.ClocknameReceivedEventArgs e)

如果编译器允许这样做,那么如果他们无法创建参数,那么应该如何调用您的方法?

要修复,可能将它们更改为公共或都受保护,或者都是内部的,具体取决于您希望如何使用它。

于 2013-03-15T08:42:10.480 回答
0

如果您对委托使用公共访问说明符,则将其删除。!它对我很有用。!

于 2014-01-07T12:48:49.680 回答
0

是的,只需将访问修饰符切换为 public 就可以了...

于 2013-03-15T08:36:19.190 回答