我正在使用devex pivot grid并希望在鼠标移动时突出显示单元格(或更改背景颜色)。
我尝试捕捉鼠标移动事件,但无法使其正常工作。这是我试过的代码:
void PivotGrid_MouseMove(object sender, MouseEventArgs e)
{
var cell = PivotGrid.Cells.GetFocusedCellInfo();
PivotGridHitInfo hitInfo = PivotGrid.CalcHitInfo(e.Location);
if (hitInfo.HitTest == PivotGridHitTest.Cell)
{
if (hitInfo.CellInfo.DataField != null)
{
// hitInfo.CellInfo.
}
}
}
我试图发现这没有谷歌但没有运气。
有人能指出一些相同的示例代码或帮我完成示例代码吗?
答案 0 :(得分:1)
您可以使用PivotGridControl.CustomDrawCell
活动。在这种情况下,您可以使用PivotGridControl.CalcHitInfo
方法来获取位于鼠标光标点的单元格。在PivotGridControl.CustomDrawCell
事件中,您可以使用PivotCustomDrawCellEventArgs.Appearance
属性更改单元格外观
这是代码:
private void pivotGridControl1_CustomDrawCell(object sender, PivotCustomDrawCellEventArgs e)
{
var info = pivotGridControl1.CalcHitInfo(pivotGridControl1.PointToClient(Cursor.Position));
if (info.CellInfo != null && info.CellInfo.RowIndex == e.RowIndex && info.CellInfo.ColumnIndex == e.ColumnIndex)
{
e.Appearance.ForeColor = CommonColors.GetWarningColor(UserLookAndFeel.Default);
e.Appearance.BackColor = CommonSkins.GetSkin(UserLookAndFeel.Default).Colors.GetColor(CommonColors.Info);
e.Appearance.Font = new Font(e.Appearance.Font, FontStyle.Bold);
}
}
此外,您需要在每次鼠标移动时强制重绘PivotGridControl
:
private void pivotGridControl1_MouseMove(object sender, MouseEventArgs e)
{
pivotGridControl1.Invalidate();
}
答案 1 :(得分:0)
我还没有对它进行调试,但也许是这样的:你记住你的生命值并使用自定义绘图。
PivotCellEventArgs ci;
void PivotGrid_MouseMove(object sender, MouseEventArgs e)
{
var cell = PivotGrid.Cells.GetFocusedCellInfo();
PivotGridHitInfo hitInfo = PivotGrid.CalcHitInfo(e.Location);
if (hitInfo.HitTest == PivotGridHitTest.Cell)
{
ci = hitInfo.CellInfo;
} else {
ci = hitInfo.CellInfo;
}
}
private void PivotGrid_CustomDrawCell(object sender, PivotCustomDrawCellEventArgs e) {
if (ci == null) return;
if (ci.ColumnIndex == e.ColumnIndex && ci.RowIndex == e.RowIndex) {
e.GraphicsCache.FillRectangle(new LinearGradientBrush(e.Bounds, Color.LightBlue,
Color.Blue, LinearGradientMode.Vertical), e.Bounds);
} else {
e.GraphicsCache.FillRectangle(new SoldidBrush(Color.White), e.Bounds);
}
e.Handled = true;
}