如何增加WinForms中ListViewItems的AutoPopDelay值? [英] How to increase AutoPopDelay value for ListViewItems in WinForms?
问题描述
您知道ListView
中的每个项目都有一个ToolTipText
属性,仅此而已!没有像AutoPopDelay
这样的属性来设置其显示时间...始终为默认值5000 ms.我试图将ToolTip
与每个项目相关联,但这似乎是不可能的.
You know that each item in a ListView
has a ToolTipText
property and that's all! There is no property like AutoPopDelay
to set its display time... Always the default value, 5000 ms. I tried to associate a ToolTip
to each item, but it seems to be impossible.
反正有没有增加ListViewItem
的ToolTipText
属性的显示时间?
Is there anyway to increase the display time for ToolTipText
property of a ListViewItem
?
推荐答案
您可以使用 TTM_SETDELAYTIME
消息到工具提示,并通过将TTDT_AUTOPOP
传递为wparam并将毫秒级延迟传递为lparam来设置其延迟.
You can get the ToolTip
of the ListView
using LVM_GETTOOLTIPS
, then send a TTM_SETDELAYTIME
message to the tooltip and set its delay by passing TTDT_AUTOPOP
as wparam and the delay in millisecond as lparam.
还要确保将ListView
的ShowItemsToolTip
属性设置为true,并且项目具有工具提示.
Also make sure ShowItemsToolTip
property of the ListView
has been set to true and the items have tooltip.
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
const int LVM_GETTOOLTIPS = 0x104E;
const int TTM_SETDELAYTIME = 0x403;
const int TTDT_AUTOPOP = 2;
private void button1_Click(object sender, EventArgs e)
{
var tooltip = SendMessage(listView1.Handle, LVM_GETTOOLTIPS, 0, 0);
SendMessage(tooltip, TTM_SETDELAYTIME, TTDT_AUTOPOP, 10000 /*milliseconds*/);
}
要设置初始延迟或重新显示延迟,请为wparam设置以下值:
To set the initial delay or the reshow delay, set the following values for wparam:
const int TTDT_AUTOMATIC = 0;
const int TTDT_AUTOPOP = 2;
const int TTDT_INITIAL = 3;
这篇关于如何增加WinForms中ListViewItems的AutoPopDelay值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!