public static int TestInstanceDelegate1(int a) { Worker w = new Worker(); w.Value = 25; SumValue executeSum = w.SumValue; int sum = executeSum(a); return(sum); }
private void TreeGrid_MouseMove(object sender, MouseEventArgs e) { Point p = this.PointToClient(Cursor.Position); bool bChanged = (preX != e.X || preY != e.Y); if (bChanged) { preX = e.X; preY = e.Y; } if (isMouseDown) { TreeListNode node = this.ViewInfo.GetHitTest(p).Node; TreeListColumn col = this.ViewInfo.GetHitTest(p).Column; if (node != null && col != null) { #region 一坨选中的单元格——方案三——排序后选择的会混乱,但是已经解决 //从第一个到当前鼠标下的单元格的位置,估计循环较大 tempTable.Rows.Clear(); #region 这个循环用了控制node的id顺序,可能可以优化 for (int i = 1; i <= idc.Count; i++) { try { if (idc[i] == node.Id && !go) { inf = i; go = true; continue; } if (idc[i] == FirstCell.ID && !go) { inf = i; go = true; continue; } if (idc[i] == node.Id && go) { enf = i; go = false; break; } if (idc[i] == FirstCell.ID && go) { enf = i; go = false; break; } } catch { } } #endregion #region 将选中的单元格的矩形存放到tempselect中,但是select里面要是有了的化,就不放进去了 double val; if (col.VisibleIndex > FirstCell.Col) { //当当前鼠标下面的单元格的列索引小于第一个单元格的列索引时 //计算选中过的列 for (int c = FirstCell.Col; c < col.VisibleIndex + 1; c++) { for (int i = inf; i < enf + 1; i++) { if (inf != 0) { if (!table.Rows.Contains(new object[] { idc[i], c })) { TreeListNode node1 = this.GetNodeByVisibleIndex(i - 1); TreeListColumn col1 = this.GetColumnByVisibleIndex(c); val = 0; double.TryParse(node1.GetDisplayText(col1), out val); tempTable.Rows.Add(new object[] { idc[i], c, node1, col1, val }); } } } } } else { //当当前鼠标下面的单元格的列索引大于第一个单元格的列索引时 for (int c = col.VisibleIndex; c < FirstCell.Col + 1; c++) { for (int i = inf; i < enf + 1; i++) { if (inf != 0) { if (!table.Rows.Contains(new object[] { idc[i], c })) { TreeListNode node1 = this.GetNodeByVisibleIndex(i - 1); TreeListColumn col1 = this.GetColumnByVisibleIndex(c); val = 0; double.TryParse(node1.GetDisplayText(col), out val); tempTable.Rows.Add(new object[] { idc[i], c, node1, col1, val }); } } } } } #endregion #endregion //立即从新绘制 this.SetFocusedNode(node); this.FocusedColumn = col; if (bChanged) { toolTip.Show(SumValue.ToString(), this, e.X + 16, e.Y + 16, 3000); } this.Invalidate(true); } } else if (toolTipText != "") { if (bChanged) { toolTip.Show(toolTipText, this, e.X + 16, e.Y + 16, 3000); } } else { toolTip.Hide(this); } }