在屏幕上绘制一个点
我需要读取屏幕上计算出的点的颜色并绘制。
VB.NET 中相当于旧版 VB 中的旧 Peek 和 Poke、PointSet 和 PointGet 命令的命令是什么?
或者,有没有一种方法可以使用标签作为 Cursor 对象,这样当我移动它时它就不会删除我的图片框内容。 我不能只制作一个光标图标,因为标签中的文本必须随着我移动光标而改变。
I need to read the color of and draw to a calculated point on the screen.
What is the VB.NET equivalent of the old Peek and Poke, or PointSet and PointGet, commands in older versions of VB?
Or in the alternative, is there a way to use a label as a Cursor object, so that it does not erase my picturebox contents as I move it around. I can't just make a Cursor Icon, because the text in the label has to change as I move the cursor.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您本身不能使用标签作为光标,但您可以将 Label 组件添加到表单中,并使用消息过滤器与光标同步移动它,如下所示:
Label 组件(在本例中为 Label1)将不要覆盖表单上的任何内容,它只会位于最上面。 只需确保标签位于表单上所有其他组件的前面,这样它就不会滑到其他任何组件的后面。 然后,您可以在适当的时候将标签的文本设置为您需要的任何内容。
编辑:要回答问题的其他部分...
要获取和设置屏幕上的任意像素,您可以使用 Windows GDI GetPixel 和 SetPixel 函数。 像这样导入它们:
像这样调用它们:
然后
其中 x 和 y 是屏幕(不是表单)坐标,颜色是要读取/设置的颜色。 您可以使用 Cursor.Position.X 和 Cursor.Position.Y 获取光标的 X/Y(如果这是您想要的 X 和 Y)。 您可以使用 PointToScreen 和 PointToClient 方法分别将窗体坐标转换为屏幕坐标和将屏幕坐标转换为窗体坐标。
请注意,一旦您设置的任何像素重新绘制,它们就会被覆盖。 请注意,这些也会在您的表单之外读/写,所以要小心。
You can't use a label as a cursor per se, but you can add a Label component to your form and move it around in sync with the cursor with a message filter, like so:
The Label component (in this example Label1) will not overwrite anything on your form, it will just sit on top. Just make sure that the Label is in front of all other components on the form so that it doesn't slide behind anything else. Then you can just set the text of the label to anything you need whenever appropriate.
Edit: To answer the other part of your question...
To get and set arbitrary pixels on the screen, you can use the Windows GDI GetPixel and SetPixel functions. Import them like this:
then call these like:
and
Where x and y are screen (not form) coordinates and color is the Color to read/set. You can get the X/Y of the cursor using Cursor.Position.X and Cursor.Position.Y, if that is the X and Y you want. You can use the PointToScreen and PointToClient methods to convert from form to screen and screen to form coordinates, respectively.
Note that any pixels you set will get overwritten as soon as whatever they are written on repaints itself. And note that these will read/write outside of your form too, so be careful.