문제

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!

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top