而不是直接注册GridMenu
,创建一个名为的通用事件处理程序Grid_ShowGridMenu
.
只需为每个网格注册相同的事件处理程序,而不是为每个网格创建单独的事件处理程序.
grdEnquiriesLevel1.ShowGridMenu += Grid_ShowGridMenu; grdApplicantsLevel1.ShowGridMenu += Grid_ShowGridMenu; grdApplicationsLevel1.ShowGridMenu += Grid_ShowGridMenu; grdInterviewsLevel1.ShowGridMenu += Grid_ShowGridMenu; private void Grid_ShowGridMenu(object sender, GridMenuEventArgs e) { GridMenu((GridView)sender, e.Point); }
现在,不是sender, e
直接传递给GridMenu
,只传递必要的值GridMenu
并更改签名,GridMenu
因此它可以更加可重用.
private void GridMenu(GridView grid, Point hitPoint) { if (grid.CalcHitInfo(hitPoint).InRow) popupMenu1.ShowPopup(Cursor.Position); }