PictureBox 控件是否有图像更改事件?
我如何知道图片框的图像何时发生变化?
是否有图像更改事件?
How do I know when the image of the picturebox change?
Is there an event for an image change?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
首先确保图像是异步加载的。为此,请设置 PictureBox 的 WaitOnLoad 属性 为 false(这是默认值)。
然后异步加载图像:
为 PictureBox 的 LoadCompleted 事件创建一个事件处理程序。当异步图像加载操作完成、取消或引发异常时,会触发此事件。
您可以在 MSDN 上找到有关此事件的更多信息:
http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.loadcompleted.aspx
First make sure that the images are loaded asynchronously. To do this set the PictureBox's WaitOnLoad property to false (which is the default value).
Then load the image asynchronously:
Create an event handler for the PictureBox's LoadCompleted event. This event is triggered when the asynchronous image-load operation is completed, canceled, or caused an exception.
You can find more information about this event on MSDN:
http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.loadcompleted.aspx
您可以将此类添加到 ToolBox 和/或从代码中添加,并使用 ImageChanged 事件来捕获图像是否更改
You can add this Class into ToolBox and/or from code and use ImageChanged event to catch if Image is Changed
如果您使用
Load()
或LoadAsync()
,则会产生加载事件,但对于Image
属性则不会。这是由您(开发人员)明确设置的,一般来说,您可以 100% 控制(参见下面的符号)。如果您确实想要(不过实际上没有意义),您可以从PictureBox
派生您自己的UserControl
并覆盖Image
> 属性,并实现您自己的事件处理程序。符号
我想您希望订阅事件的一个事件是,如果您正在使用某些更改图像属性的第三方组件或控件,并且您希望在发生这种情况时实现某种子例程。在这种情况下,这将是需要 ImageChanged 事件的一个原因,因为您无法控制何时设置图像。不幸的是,仍然没有办法避免这种情况。
There are load events if you use
Load()
orLoadAsync()
, but not for theImage
property. This is explicitly set by you (the developer) and is generally speaking in 100% of your control (see notation below). If you really wanted to though (there isn't really a point, though), you can derive your ownUserControl
fromPictureBox
and override theImage
property, and implement your own event handler.Notation
I suppose one event you would want an event to subscribe to is if you are using some third-party component or control that changes the image property, and you want to implement some sort of sub routine when this happens. In this event it would be a reason to need a ImageChanged event since you don't have control over when the image is set. Unfortunately there still isn't a way to circumvent this scenario.
Paint
事件正在运行:The
Paint
event is working: