ListView控件光标改变和放大器;闪烁 [英] ListView Cursor changing & flickering

查看:224
本文介绍了ListView控件光标改变和放大器;闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变,当光标出现在一个项目上的ListView标准出现的光标。但是我得到一个闪烁效果鼠标变为手指游标,然后回到我问它是。

I'm trying to change the cursor that appears on a standard ListView when the cursor appears over an item. However I am getting a flickering effect as the mouse is changed to a finger cursor, and then back to what I asked it to be.

我试图隔离此闪烁/更改为手形光标,但不能揣摩出它的存在的或如何阻止它。复制此...

I'm trying to isolate this flicker/changing to the hand cursor but can't figure out where it's occuring or how to stop it. To replicate this...

1)创建,上面有一个ListView的形式。
2)添加一个图像列表和一些图像。视图设置为大图标模式。
3)添加一些项目到ListView。

1) Create a form with a ListView on it. 2) Add an image list and some images. Set the view to the large icon mode. 3) Add some items to the ListView.

的MouseMove 事件添加到的ListView

private void listView1_MouseMove(object sender, MouseEventArgs e)
{
    ListViewItem selected = this.listView1.GetItemAt(e.X, e.Y);
    if (selected == null)
    {
        base.Cursor = Cursors.Default;
    }
    else
    {
        base.Cursor = Cursors.No;
    }
}

执行应用程序,在项移动鼠标。您应该看到光标没有闪烁之间(无输入光标)和手指指针,当你在某个项目上。现在的问题是如何确保它只是显示没有光标和不闪烁。 (C#.NET)。

Execute the app, moving the mouse over an item. You should see the cursor flickering between the No (no entry cursor) and the finger pointer when you're over an item. The question is how to ensure it just displays the No cursor and to not flicker. (C# .NET).

我试过同时重写的OnMouseMove和OnMouseHover久违确保这些不设置任何东西。我也尝试重写光标属性,说'只设置为默认或者没有游标',而且也不能工作。

I've tried override both OnMouseMove and OnMouseHover to returning to ensure these don't set anything. I've also tried overriding the Cursor property and saying 'only set to default or no cursors' and that didn't work either.

任何帮助的AP preciated。

Any help's appreciated.

伊恩

推荐答案

的问题是,C#ListView控件基本上是围绕Windows列表视图控件的包装。所以,当我们设置光标到箭头,基础ListView控件总是默认为手形指针,而我们在C#中的ListView类设置希望它成为一个箭头。这就是为什么我们得到的闪烁,因为底层控制是回到原来​​手。

The problem is that C# ListView Control is basically a wrapper around windows List View Control. So when we set the cursor to Arrow, the underlying listview control always defaulted to Hand cursor while our setting in the C# ListView class wanted it to be an Arrow. That's why we were getting that flickering, because underlying control was reverting back to Hand.

下面是你需要添加code:

Here is the code that you need to add:

public const uint LVM_SETHOTCURSOR = 4158;

[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

SendMessage(listView1.Handle, LVM_SETHOTCURSOR, IntPtr.Zero, Cursors.Arrow.Handle);

这是非常重要的,你因为届时基础ListView控件是完全初始化从表单的onLoad事件调用SendMessage函数!

It's very important that you call the SendMessage from your Form's onLoad event because by then the underlying ListView control is completely initialized!

这是pretty其实很简单,有一个伟大的日子! :)

It's pretty simple actually, Have a great day! :)

这篇关于ListView控件光标改变和放大器;闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆