c# - Smooth Expanding and Collapsing Animation for WinForms -
im trying smooth expanding , collapsing animation form. current animation jittery , non consistent. heres gif of animation. there way doesnt freeze form?
private void showhidetoggle_checkstatechanged(object sender, eventargs e) { if (showhidetoggle.checked) //checked = expand form { showhidetoggle.text = "<"; while (width < originalwidth) { width++; application.doevents(); } } else { showhidetoggle.text = ">"; while(width > 24) { width--; application.doevents(); } } }
create timer
:
timer t = new timer(); t.interval = 14; t.tick += delegate { if (showhidetoggle.checked) { if (this.width > 30) // set form.minimumsize otherwise timer keep going, permanently try decrease size. this.width -= 10; else t.stop(); } else { if (this.width < 300) this.width += 10; else t.stop(); } };
and change code to:
private void showhidetoggle_checkstatechanged(object sender, eventargs e) { t.start(); }
Comments
Post a Comment