【发布时间】:2018-09-04 19:35:04
【问题描述】:
最终目标是为 ListBox 中的对象添加工具提示。我发现了一些这样做的例子,即:
private void OnListBoxMouseMove ( object sender, MouseEventArgs e )
{
string strTip = "";
// Get the item
int nIdx = listBox1.IndexFromPoint(e.Location);
if ((nIdx >= 0) && (nIdx < listBox1.Items.Count))
strTip = listBox1.Items[nIdx].ToString();
toolTip1.SetToolTip(listBox1, strTip);
}
但是,我的页面将其作为System.Windows.Input.MouseEventArgs 对象而不是Systems.Windows.Forms 放入,因此e.Location 不存在。
是否可以从正确的命名空间接收此事件?另一个因素可能是 ListBox 在 System.Windows.Controls 命名空间中?
【问题讨论】:
-
这可能有用 - GetPosition
-
System.Windows.Input 是 wpf,System.Windows.Forms 是 winforms。您要么使用其中一个,要么使用另一个,但很少将两者结合在一个窗口中。
-
您正在开发 WPF 或 Windows 窗体应用程序吗?