为什么picturebox image属性绑定后不会刷新? [英] Why does picturebox image property does not refresh if bound?
问题描述
我的情况很简单:
-表格
-以某种方式更改pictureBox1的按钮
-picturebox1(带有一些图像)
-picturebox2(干净)
-在Form_Load中添加以下行:
绑定b = new Binding("Image",pictureBox1,"Image");
pictureBox2.DataBindings.Add(b);
一开始,我就会在两个屏幕上看到相同的图像...好!
但是,当我更改picturebox1时,picturebox2并没有跟随我...我需要刷新它!为什么?如果我正确理解绑定"技术,则在绑定属性后,我想忘记picturebox2,而只需修改picturebox1.有没有办法让make picturebox1自动刷新?有点像是一个事件(我还没有找到它!),它告诉绑定源已更改...
最好,谢谢.
Hi,
my scenario is very simple:
- a form
- a button to change somehow pictureBox1
- picturebox1 (with some image)
- picturebox2 (clean)
- into Form_Load I add these lines:
Binding b = new Binding("Image", pictureBox1,"Image");
pictureBox2.DataBindings.Add(b);
As soon as I start, I see the same images on both...OK!
But then, when I change picturebox1, picturebox2 does not follow me... I need to refresh it! Why? If I correctly understand "Binding" technology, once the property is bound, I''d like to forget picturebox2 and just modify picturebox1. Is there a way to obtain make picturebox1 autorefresh? Somethink like an event (I did not find it yet!) who tells binding source has changed...
Thanks, best.
推荐答案
看看此页: ^ ]特别是显示哪些类可以作为数据源的表.
他们必须实现IBindingList或ITypedList或实现或成为IList.您可以将PictureBox绑定到其中的任何一个,但是AFAIK不能将PictureBox用作绑定源.
如果PictureBox发生ImageChanged事件,则可以将其挂接.相反,您可以挂钩Paint事件并执行以下操作:
Take a look at this page: Binding Class[^] specifically the table that shows what classes can be a datasource.
They have to implement IBindingList or ITypedList or implement or be an IList. You can bind a PictureBox to any of those, but AFAIK you can''t use a PictureBox as your binding source.
If PictureBox had an ImageChanged event, you could just hook that. Instead, you could hook the Paint event and just do:
private void pictureBox2_Paint(object sender, PaintEventArgs e)
{
base.OnPaint(e);
pictureBox1.Image = pictureBox2.Image;
}
这篇关于为什么picturebox image属性绑定后不会刷新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!