一.渐显效果
1.构造函数
public StartForm() { this.TransparencyKey = Color.Transparent;// this.DoubleBuffered = true;//这句必须加上,不然渐显时 InitializeComponent(); this.Opacity = 0.01d; } 2.在Form_Shown事件加入如下代码,不能在Load事件中 EffectFormFade(this, 200, true, false);//函数源码在下方 //窗体渐显渐隐效果 public static void EffectFormFade(Form myForm, int numPeriod, bool inOrOut, bool closeAtLast) { int inFlag = (inOrOut) ? 1 : -1; myForm.Invoke(new EventHandler(delegate { for (int i = 0; i < numPeriod; i++) { myForm.Opacity += inFlag * 1d / numPeriod; Application.DoEvents(); if (myForm.Opacity == 0d || myForm.Opacity == 100d) { if (closeAtLast) { myForm.Close(); } } } })); }
二.渐隐效果
EffectFormFade(this, 200, false, true);
posted on 2012-03-13 14:59 阅读( ...) 评论( ...)