【问题标题】:Get coordinates of ListView items' subitems relative to the Form获取 ListView 项的子项相对于 Form 的坐标
【发布时间】:2014-10-10 12:28:29
【问题描述】:

我有一个ListView,有 4 个项目,每个项目有 3 个子项目。

现在,例如,我想获取第 2 项子项 2 相对于 Form 的坐标(位置)。

我该怎么做?

【问题讨论】:

标签: c# winforms listview coordinates


【解决方案1】:

您正在寻找ListViewSubItemBounds 属性。下面是该属性的简单用法:

private void listView1_MouseDown(object sender, MouseEventArgs e)
{
    var bound = listView1.Items[1].SubItems[1].Bounds;

    if (e.X > bound.Left && e.X < bound.Right && e.Y > bound.Top && e.Y < bound.Bottom)
    {
        MessageBox.Show("hello world");
    }
}

【讨论】:

  • 很高兴听到它有帮助:)
  • 您也可以使用“bound.Contains (e.Location)”来获得更紧凑的代码。
猜你喜欢
  • 2013-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-06
  • 1970-01-01
相关资源
最近更新 更多