相关疑难解决方法(0)

从拥有类外部调用C#事件?

在任何情况下是否有可能实现这一目标?

我目前的情况如下:

public class CustomForm : Form
{
    public class CustomGUIElement
    {
    ...
        public event MouseEventHandler Click;
        // etc, and so forth.
    ...
    }

    private List<CustomGUIElement> _elements;

    ...

    public void CustomForm_Click(object sender, MouseEventArgs e)
    {
        // we might want to call one of the _elements[n].Click in here
        // but we can't because we aren't in the same class.
    }
}
Run Code Online (Sandbox Code Playgroud)

我的第一个想法是有一个类似的功能:

internal enum GUIElementHandlers { Click, ... }
internal void CustomGUIElement::CallHandler(GUIElementHandler h, object[] args) {
    switch (h) {
        case Click: …
Run Code Online (Sandbox Code Playgroud)

c# events inheritance

13
推荐指数
2
解决办法
2万
查看次数

标签 统计

c# ×1

events ×1

inheritance ×1