C#:检索没有发送方对象的已触发事件的源

时间:2017-04-12 15:53:03

标签: c#

我正在使用GMaps.NET控件,我抓住了这个事件" TileLoadComplete":

http://www.nudoq.org/#!/Packages/GMap.NET.WindowsForms/GMap.NET.WindowsForms/GMapControl/E/OnTileLoadComplete

我在运行时创建了几个控件,并且它们共享该事件的相同功能:

for (int i = 0; i < 5; i++)
{
    GMap.NET.WindowsForms.GMapControl control = new GMap.NET.WindowsForms.GMapControl();
    control.Manager.Mode = AccessMode.ServerOnly;
    control.MapProvider = GMap.NET.MapProviders.GoogleSatelliteMapProvider.Instance;
    control.OnTileLoadComplete += Control_OnTileLoadComplete;
    // set other map properties
}

private void Control_OnTileLoadComplete(long ElapsedMilliseconds)
{
    // who has completed the loading?
}

因为事件签名中没有发件人对象,我想知道是否有另一种方法可以知道哪个控件已完成加载地图。

1 个答案:

答案 0 :(得分:3)

这会有用吗?使用lambda捕获发件人:

<span data-toggle="popover" class="fa fa-exclamation-circle fa-lg" [attr.data-content]="getTooltipMsg('lastName')"></span>

您必须更新for (int i = 0; i < 5; i++) { GMap.NET.WindowsForms.GMapControl control = new GMap.NET.WindowsForms.GMapControl(); //...snip... control.OnTileLoadComplete += x => Control_OnTileLoadComplete(control, x); } private void Control_OnTileLoadComplete(object sender, long ElapsedMilliseconds) { // who has completed the loading? // the sender, that's who! } 的每次使用才能使用该lamdba。如果只有“发件人”属于Control_OnTileLoadComplete类型,您可以将类型从object sender更改为GMapControl sender