列表框经常加载 [英] listbox getting frequently loaded

查看:75
本文介绍了列表框经常加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个位图,其中我只拍了9个像素。



每个像素都有rgb值...我创建了一个3 * 3的数组尺寸。



每个像素rgb值分别取出并加载到一个列表框中。



毕竟迭代列表框中的值将为27 ...



直到这里它没事。



当我运行应用程序,,,列表框加载了所有27个值...但是在10到15个secons ... ic之后,计数再次增加到54 ...有时81 ...等等...为什么会发生这种情况



i已经将bmp放在一个图片框中..在表格中......代码写在picturebox_paint事件中...是这是一个错误...



首先当R计算为第一个像素时,它将转到一个名为add ...的函数,来自picturebox1_paint event..where listbox将添加R值..然后再次循环...类似于G和B值。



这里的简要代码是:



pictureBox1_Paint event

{

for(i = 0 ;我< 3; i ++)

{



for(j = 0; j< 3; j ++)

{

颜色pixelColor = bm.GetPixel(i,j);

b = pixelColor.R;

ADDINARRAY(b);



c = pixelColor.G;

ADDINARRAY(c);

d = pixelColor.B;

ADDINARRAY(d);













}

}

}





//这是要在列表框中加载的项目的代码

void ADDINARRAY(int value)

{



listBox1.Items.Add(value);

}

i have a bitmap in which i am taking only 9 pixels.

each pixel will have rgb value...i have created an array of 3 * 3 size.

each pixel rgb value is taken separately and loaded in a list box.

after all iterations the no of values in list box will be 27...

till here it is fine.

when i run the application ,,,the listbox gets loaded with all 27 values..but after some 10 to 15 secons...i c the count is increasing again to to 54...sometimes 81...and so on...why is this happening

i have taken the bmp in a picture box..in the form...the code is written in picturebox_paint event...is this a mistake...

first when R is calculated for fist pixel it will go to a function called add...from picturebox1_paint event..where the listbox will get added with R value..and then goes to loop again...similarily for G and B values.

here is the brief code:

pictureBox1_Paint event
{
for (i = 0; i < 3; i++)
{

for (j = 0; j < 3; j++)
{
Color pixelColor = bm.GetPixel(i, j);
b = pixelColor.R;
ADDINARRAY(b);

c = pixelColor.G;
ADDINARRAY(c);
d = pixelColor.B;
ADDINARRAY(d);






}
}
}


// this is the code for items to get loaded in listbox
void ADDINARRAY(int value)
{

listBox1.Items.Add(value);
}

推荐答案

代码是用picturebox_paint事件

是。



每次需要由系统更新PictureBox时都会调用Paint事件。它正在做它应该做的事情。



将代码移动到更合适的事件,或者在用新数据填充之前清除列表框内容。 />
就个人而言,我会同时做这两件事!
"the code is written in picturebox_paint event"
Yes.

The Paint event is called every time the PictureBox needs to be updated by the system. It is doing exactly what it should.

Either move the code to a much more appropriate event, or Clear the Listbox content before you fill it with new data.
Personally, I''d do both!


这篇关于列表框经常加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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