0
我想获取ListView项目/子项目的位置。我的意思是,我想为这个子项目获得一个左和顶。这是我的意思是:Listview子项目位置(C#窗体)
。
我尝试这样做:
int item_x = list.Items[1].SubItems[2].Bounds.X;
int item_y = list.Items[1].SubItems[2].Bounds.Y;
但它似乎并没有给予正确的位置我想要的。
我想获取ListView项目/子项目的位置。我的意思是,我想为这个子项目获得一个左和顶。这是我的意思是:Listview子项目位置(C#窗体)
。
我尝试这样做:
int item_x = list.Items[1].SubItems[2].Bounds.X;
int item_y = list.Items[1].SubItems[2].Bounds.Y;
但它似乎并没有给予正确的位置我想要的。
好的,看起来我之前写的是正确的。它只需要进行一些加减运算,然后显示如下:http://spunit.cf/x/scrn370.png。
感谢让我意识到这=)。
下面是它的代码:
int item_l = list.Items[1].SubItems[2].Bounds.Left + 3;
int item_t = list.Items[1].SubItems[2].Bounds.Top + 29;
int item_w = list.Items[1].SubItems[2].Bounds.Width - 1;
int item_h = list.Items[1].SubItems[2].Bounds.Height - 1;
ListView listt = new ListView();
Controls.Add(listt);
listt.BringToFront();
listt.Bounds = new Rectangle(new Point(item_l, item_t), new Size(item_w, item_h));
我认为你需要把你的ListView控件的坐标关注。我认为(我不知道或测试你的代码是否工作)你的代码将返回相对于你的列表视图的坐标。如果你的列表视图在容器中而不是直接在表单上,你应该考虑到这一点 – 2014-10-19 21:00:12
实际上这些数字对我来说看起来很好。正确的坐标在列表视图中,标题高度包括..他们是什么,你会期望什么? – TaW 2014-10-19 21:17:29
它只是不可能是正确的......这是位置变成http://spunit.cf/x/scrn352.png的地方 – spunit 2014-10-19 21:30:32