How to increase AutoPopDelay value for ListViewItems in WinForms?

后端 未结 3 1522
故里飘歌
故里飘歌 2021-01-23 01:22

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 displa

相关标签:
3条回答
  • 2021-01-23 02:10

    MouseHover fires once per control - so is never updated as you move to different items.

    Use ListView.ItemMouseHover to accomplish what you need.

    void listView1_ItemMouseHover(object sender, ListViewItemMouseHoverEventArgs e)
    {
        this.toolTip1.SetToolTip(e.Item.ListView, e.Item.ToolTipText);
    }
    
    0 讨论(0)
  • 2021-01-23 02:12

    To Hans Passant.

    I used this code in MouseHover event:

        Point pntOnList = lsvSource.PointToClient
            (new Point(Cursor.Position.X, Cursor.Position.Y));
        ListViewItem lsviUnderMouse =
            lsvSource.GetItemAt(pntOnList.X, pntOnList.Y);
        if (lsviUnderMouse != null)
        {
            ttipDetails.SetToolTip(lsvSource, lsviUnderMouse.ToolTipText);
            ttipDetails.Active = true;
        }
        else
        {
            ttipDetails.Active = false;
        }
    

    But it behaves strangely. Actually the ToolTip's text is always outdated.

    0 讨论(0)
  • 2021-01-23 02:19

    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.

    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*/);
    }
    

    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;
    
    0 讨论(0)
提交回复
热议问题