本文介绍了Picturebox:更新时内容消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我编写了一个简单的程序,以通过条形图显示街道外观的数量.但是当我画新的时,旧的就消失了.
Hi there,
i make a simple program to display the number of street''s appearances through bar chart. but when i draw new one, the old one disappear.
void PicStreetPaint(object sender, PaintEventArgs e)
{
if(bClear){
e.Graphics.Clear(Color.White);
}
else{
// s = street-th, r = height of bar
Brush bColor = new SolidBrush(Color.FromName(aColor[s]));
grStreet.FillRectangle(bColor, s * 30, 0, 30, r * 20);
}
}
这是旧代码,当我移动表格时,内容消失了,因为它没有重绘.
this is old code, when it i move form around, contents disappear because it not redraw.
public void UpdateStreet(int number)
{
if(number == 0){
return;
}
int[] Street = new int[] {1,1,1,2,2,2,3,3,3,4,4,4,
5,5,5,6,6,6,7,7,7,8,8,8,
9,9,9,10,10,10,11,11,11,12,12,12};
string[] aColor = new string[]{"Silver", "Tomato", "Red", "Yellow", "GreenYellow", "Green", "Teal", "DodgerBlue", "SlateBlue", "Indigo", "Crimson", "Plum"};
int r = 0, s = 0;
Graphics grStreet = picStreet.CreateGraphics();
Brush bColor;
number -= 1; // adjust to array
s = Street[number] - 1; // get street-th
bColor = new SolidBrush(Color.FromName(aColor[s]));
street[s] += 1; // update the number of street's appearance
r = street[s]; // height of bar = number of street's appearance
grStreet.FillRectangle(bColor, s * 30, 0, 30, r * 20);
picStreet.Update();
}
非常感谢.
thank you very much.
推荐答案
这篇关于Picturebox:更新时内容消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!