即使在应用程序之外,如何使图像跟随光标?
在带有 Winforms 的 VB.Net 中,即使图像离开表单,如何使图像跟随光标?我想在拖放操作期间执行此操作。 BCL 和/或 GDI 比 P/Invokes 更适合我的用例。
如果您熟悉 PeaZip,它会在从其界面拖动文件时执行此类操作。
In VB.Net with Winforms how do I make an image follow the cursor even when it leaves the form? I want to do this during a drag and drop operation. BCL and/or GDI is better for my usecase than P/Invokes.
If you are familiar with PeaZip, it does something of this sort when dragging a file from it's interface.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有关使用 P/Invokes 执行此操作的信息:
CodeProject:自定义鼠标光标 (VB.NET)< /a>
文章中的关键内容:
For information on doing it with P/Invokes:
CodeProject: Custom Mouse Cursors (VB.NET)
Key ones from the article:
最简单的方法似乎只是简单地将鼠标光标更改为默认鼠标光标和您想要跟随它的图像的合成图像。完成后将其更改回默认鼠标光标。
有多种方法可以使用 P/Invokes 来做到这一点,但这里有一个关于如何在没有它们的情况下做到这一点的理论。在我遇到的示例中,P/Invoke 主要用于获取指向已创建并编组到非托管内存中的游标结构的指针。然后,指针被传递给 System.Windows.Forms.Cursor 类的构造函数。
但是,接受内存流的游标类中有一个重载。如果可以在内存流中构造相同的游标文件结构,则可以将其传递到构造函数中,这将为我们提供要更改的游标。 “cur”图像文件与“ico”文件非常相似,并且相当简单。它由一个小标题、一个图像目录和最后的图像数据本身组成(维基百科条目ICO 文件格式)。构建然后写入内存流应该不会太难。
The easiest way to do this seems to be just plain changing the mouse cursor to a composite image of the default mouse cursor and the image you want following it. Then after you are finished change it back to the default mouse cursor.
There are ways to do this with P/Invokes, but here is a theory on how to do it without them. In examples I've run across P/Invokes are primarily used to get a pointer to/for a cursor Structure that has been created and Marshalled into unmanaged memory. Then the Pointer is passed to the Constructor for the System.Windows.Forms.Cursor Class.
However, there is an overload in the Cursor Class that accepts a Memory Stream. If the same cursor file structure could be constructed in a Memory Stream, it could then be passed into the Constructor, which would give us the Cursor to change to. The 'cur' image file is very similar to an 'ico' file, and is fairly simple. It consists of a small header, an image directory, and finally the image data itself (Wikipedia entry on the ICO file format). This should not be too hard to construct and then write out to a Memory Stream.