C# hScrollBar 的简单问题
代码是这样的,为什么结果输出变成图片里的这样一下子有两个了,不懂啊privatevoidhScrollBar1_Scroll(objectsender,ScrollEve...
代码是这样的,为什么结果输出变成图片里的这样一下子有两个了,不懂啊
private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
int a, b, c,sum=0;
a = hScrollBar1.Value;
b = hScrollBar2.Value;
for (c = 1; c <= b; c++)
{
sum += a;
label1.Text = label1.Text + a + " " + '\n';
a = a * 10 + hScrollBar1.Value;
}
label1.Text = label1.Text + "------------------------" + '\n' + sum;
} 展开
private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
int a, b, c,sum=0;
a = hScrollBar1.Value;
b = hScrollBar2.Value;
for (c = 1; c <= b; c++)
{
sum += a;
label1.Text = label1.Text + a + " " + '\n';
a = a * 10 + hScrollBar1.Value;
}
label1.Text = label1.Text + "------------------------" + '\n' + sum;
} 展开
1个回答
展开全部
你可能是拖动了一下滚动条,事实上,每当你拖动的时候label1就会增加一行,你可以修改如下:
private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
//增加了一行代码:
label1.Tezxt="";
int a, b, c,sum=0;
a = hScrollBar1.Value;
b = hScrollBar2.Value;
for (c = 1; c <= b; c++)
{
sum += a;
label1.Text = label1.Text + a + " " + '\n';
a = a * 10 + hScrollBar1.Value;
}
label1.Text = label1.Text + "------------------------" + '\n' + sum;
}
不知道能不能实现你的设计意图
private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
//增加了一行代码:
label1.Tezxt="";
int a, b, c,sum=0;
a = hScrollBar1.Value;
b = hScrollBar2.Value;
for (c = 1; c <= b; c++)
{
sum += a;
label1.Text = label1.Text + a + " " + '\n';
a = a * 10 + hScrollBar1.Value;
}
label1.Text = label1.Text + "------------------------" + '\n' + sum;
}
不知道能不能实现你的设计意图
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询