鼠标位置并给出位置颜色 [英] mouse position and give the position color

查看:90
本文介绍了鼠标位置并给出位置颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这段代码中我将图片加载到图片框并通过鼠标点击事件我想选择2点并给每一个不同的颜色我的问题是pictureBox鼠标点击不响应

in this code I load image to picturebox and by mouse click event I want to select 2 point and give each one different color my problem is the pictureBox Mouse Click not respond

推荐答案

不要 PictureBox ,并且在大多数情况下,不要使用 SetPixel 。第一个没有帮助你,只会增加麻烦,需要一些额外的资源和你的开发时间,第二个是非常慢(但文件,如果你只想设置几个像素之一)。我告诉你要做的事。



我解释了为什么不使用 PictureBox 以及该怎么做我过去的回答:

在图片框中附加图片 [ ^ ],

如何从旧图纸中清除面板 [ ^ ],

在C#中绘制一个矩形 [ ^ ]。



鼠标位置问题将自动解决:鼠标事件参数实例(传递给事件处理程序)将为您提供控件坐标中的鼠标位置以及图形。



有关图像渲染的更多细节,请参阅我过去的答案:

什么样的俏皮方法是Paint? (DataGridViewImageCell.Paint(...)) [ ^ ],

在面板上捕获绘图 [ ^ ],

mdi子表单之间的绘制线 [ ^ ],

另见:如何加快我的vb.net应用程序? [ ^ ],

用C#.net鼠标滚轮缩放图像 [ ^ ]。



你实际上可以使用 SetPixel ,但只有你想设置一个或几个,但这在实践中几乎不需要。在所有其他情况下,为了获得合理的性能,您需要使用 LockBits

https://msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits% 28v = vs.110%29.aspx [ ^ ]。



您可以在此处找到代码示例:https://msdn.microsoft.com/en-us/library/5ey6h79d(v=vs .110).aspx [ ^ ]。



-SA
Don't PictureBox and, in most cases, don't use SetPixel. First one does not help you, only adds hassles and takes some extra resources and your development time, second one is prohibitively slow (but file if you want just to set one of few pixels). I'll tell you want to do.

I explained why not using PictureBox and what to do instead in my past answers:
Append a picture within picturebox[^],
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^].

And the problem with mouse position will be solved automatically: your mouse event argument instance (passed to your event handler) will give you the mouse position in the control's coordinate, as well as your graphics.

For further detail in image rendering, please see my past answers:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^],
Drawing Lines between mdi child forms[^],
see also: How to speed up my vb.net application?[^],
Zoom image in C# .net mouse wheel[^].

You can actually use SetPixel, but only if you want to set one or just few, but this is almost never needed in practice. In all other cases, for reasonable performance, you need to use LockBits:
https://msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits%28v=vs.110%29.aspx[^].

You will find a code sample here: https://msdn.microsoft.com/en-us/library/5ey6h79d(v=vs.110).aspx[^].

—SA


这篇关于鼠标位置并给出位置颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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