数据绑定图片框背景到列表索引? [英] Data bind picturebox backcolor to list index?
问题描述
有人知道如何将图片框的背景颜色绑定到列表的某个索引吗?
Does anybody know how to bind a picturebox's backcolor to a certain index of a list?
我现在已经尝试了两天而且正在拉我的发单。
I have been trying for two days now and am at the point of pulling my hair out.
public override void Refresh()
{
base.Refresh();
Controls.Clear();
items.Clear();
if (palette != null && palette.Color.Count > 0)
{
for (int i = 0; i < palette.Color.Count; i++)
{
int x = i % columns;
int y = i / columns;
PictureBox pictureBox = new PictureBox();
pictureBox.Location = new Point(x * 16, y * 16);
pictureBox.Size = new Size(16, 16);
pictureBox.BackColor = palette.Color[i];
pictureBox.Parent = this;
pictureBox.DataBindings.Add("BackColor", Palette.Color[i], "", true, DataSourceUpdateMode.OnPropertyChanged);
//pictureBox.BindingContext[palette.Color].Position = i; <-- throws null object exception
pictureBox.Enabled = false;
items.Add(pictureBox);
}
Size = new Size(columns*16, rows*16);
}
}
调色板是一个持有颜色列表,最多16个。
palette is a class that hold a list of colors, up to 16 currently.
和项目只是一个跟踪我的图片框的列表。
and items are just a list for keeping track of my pictureboxes.
推荐答案
您好Shadowblitz16,
Hi Shadowblitz16,
> ;>如何将图片框的背景颜色绑定到列表的某个索引?
>>how to bind a picturebox's backcolor to a certain index of a list?
我认为您使用该列表来存储pictureBox的BackColor, ;如果是,请更改代码:
I think you use the list to store the pictureBox's BackColor, if so, please change the code:
items.Add(pictureBox);
收件人:
items.Add(pictureBox.BackColor);
如果我误解了您的问题,请告诉我并提供更多代码,以便我可以对其进行测试。
If I misunderstand your question, please let me know and provide more code so that I can test it.
希望有所帮助!
最诚挚的问候,
Stanly
这篇关于数据绑定图片框背景到列表索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!