逐渐或平滑地改变对象大小(复选框列表)?
C# 问题
这是我正在尝试做的事情。当我单击按钮时,我希望复选框列表的大小顺利地从 (200,10) 更改为 (200,100)。我成功地改变了尺寸,但我希望它看起来很平滑。
这是我编写的代码:
private void Form1_Load(object sender, EventArgs e)
{
timer1.Interval = 1;
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (checkedListBox1.Height < 100)
{
checkedListBox1.Size = new Size(checkedListBox1.Size.Width, checkedListBox1.Size.Height + 1);
}
else
{
timer1.Enabled = false;
}
}
我使用此编码平滑地移动对象,但从不更改大小。
因此,当您运行此代码时,该框只会闪烁,看起来它试图更改大小,但事实并非如此,并且循环永远不会结束。
谢谢!
C# question
Here is what I am trying to do. When I click a button, I want the checkboxlist to smoothly change from say (200,10) to (200,100) in size. I am successful at getting to size to change instantaneously, but I want it to look smooth.
Here is the code I wrote:
private void Form1_Load(object sender, EventArgs e)
{
timer1.Interval = 1;
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (checkedListBox1.Height < 100)
{
checkedListBox1.Size = new Size(checkedListBox1.Size.Width, checkedListBox1.Size.Height + 1);
}
else
{
timer1.Enabled = false;
}
}
I have used this coding to move objects smoothly, but never to change sizes.
So when you run this code, the box just flickers and it seems like its trying to change size, but it doesn't, and the loop never ends.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将 IntegralHeight 设置为
false
表示框的高度可以不是项目高度的倍数。对于闪烁,您可能应该 双缓冲包含此控件的表单。
You need to set IntegralHeight to
false
to that the box can be a height that is not a multiple of the item height.For the flickering, you should probably double-buffer the form which contains this control.