In Winform, The ListView mouse moves and the toolTip displays information, listviewtooltip
I used ListView when I was working on a hotel management system today. I suddenly thought about whether I could provide details about the specific room when I move my mouse over a certain item!
First, set the MouseMove event of Listview.
1. Get the current coordinate item
ListViewItem lvi = this. listView. GetItemAt (e. X, e. Y );
2. Determine whether a selected item exists. If yes, the corresponding information is displayed.
If (lvi! = Null)
{
ToolTip. show ("Test", listView, new Point (e. X, e. Y), 1000 );
ToolTip. Active = true;
}
: There is a problem. When you place the cursor over an item, the information is flashing constantly! The reason is that when the mouse does not move, it will also respond to the event, and all the problems will be solved by adding the following code.
First define a variable private Point pointView = new Point (0, 0); // location
Then, make judgments when displaying information.
If (pointView. X! = E. X | pointView. Y! = E. Y) // prevents flickering
{
ToolTip. show ("Test", listView, new Point (e. X, e. Y), 1000 );
PointView. X = e. X;
PointView. Y = e. Y;
ToolTip. Active = true;
} Else
{
ToolTip. Hide (listView );
PointView = new Point (e. X, e. Y );
}
Above, solve the problem!