<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> /**//// <summary>
/// 傳遞子控件事件到父窗體的中間事件
/// </summary>
public event MouseEventHandler MapControl_MouseMove;
/**//// <summary>
/// 傳遞子控件事件到父窗體的中間事件
/// </summary>
public event EventHandler ViewChanged;
/**//// <summary>
/// 控件關閉事件
/// </summary>
public event EventHandler Closed;
/**//// <summary>
/// 在地圖控件上點擊後觸發
/// </summary>
public event MouseEventHandler MapControl_MouseClick;
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> void mapControl1_MapControl_MouseMove ( object sender, MouseEventArgs e )
{
if ( this.MapControl_MouseMove != null )
{
//把事件轉發出去
MapControl_MouseMove ( this, e );
}
}
void mapControl1_MapControl_MouseClick ( object sender, MouseEventArgs e )
{
if ( this.MapControl_MouseClick != null )
{
MapControl_MouseClick ( this, e );
}
}
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> /**//// <summary>
/// 爲窗體添加子控件
/// </summary>
/// <param name="childForm">需要添加的子窗體</param>
public void AddChildForm ( ViewMap childForm )
{
if ( !childFormList.Contains ( childForm ) )
{
if ( !( childFormList.Count + 1 > _maxChildForm ) )
{
this.childFormList.Add ( childForm );
}
else
{
MessageBox.Show ( _OVER_MAX_CHILDFORM_COUNT );
return;
}
}
childForm.MapControl_MouseMove += new MouseEventHandler ( vm_MapControl_MouseMove );
childForm.ViewChanged += new EventHandler ( vm_ViewChanged );
childForm.Closed += new EventHandler ( childForm_Closed );
childForm.MapControl_MouseClick += new MouseEventHandler ( childForm_MapControl_MouseClick );
SetChildFormLocation ();
this.Controls.Add ( childForm );
}
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> void vm_MapControl_MouseMove ( object sender, MouseEventArgs e )
{
foreach ( ViewMap vm in childFormList )
{
if ( !sender.Equals ( vm ) )
{
vm.DrawAssistLine ( e.Location );
}
}
}
void vm_ViewChanged ( object sender, EventArgs e )
{
//遍歷所有子窗體,如當前sender不爲本身,執行事件
MapControlEventArg mce = e as MapControlEventArg;
foreach ( ViewMap vm in childFormList )
{
if ( !sender.Equals ( vm ) )
{
vm.SetCenter ( mce.ZoomLevel, mce.Center );
}
}
}