c# - Fading the background while modal dialog is shown -
when shutting down windows xp system, displays modal dialog box while background fades grayscale. achieve same effect in of programming languages in tag list. can help?
this pretty easy winforms. need borderless maximized window gray background opacity change timer. when fade done, can display dialog borderless , uses transparencykey make background transparent. here's sample main form implements this:
public partial class form1 : form { public form1() { initializecomponent(); this.formborderstyle = formborderstyle.none; this.windowstate = formwindowstate.maximized; this.backcolor = color.fromargb(50, 50, 50); this.opacity = 0; fadetimer = new timer { interval = 15, enabled = true }; fadetimer.tick += new eventhandler(fadetimer_tick); } void fadetimer_tick(object sender, eventargs e) { this.opacity += 0.02; if (this.opacity >= 0.70) { fadetimer.enabled = false; // fade done, display overlay using (var overlay = new form2()) { overlay.showdialog(this); this.close(); } } } timer fadetimer; }
and dialog:
public partial class form2 : form { public form2() { initializecomponent(); formborderstyle = formborderstyle.none; this.transparencykey = this.backcolor = color.fuchsia; this.startposition = formstartposition.manual; } protected override void onload(eventargs e) { base.onload(e); this.location = new point((this.owner.width - this.width) / 2, (this.owner.height - this.height) / 2); } private void button1_click(object sender, eventargs e) { this.dialogresult = dialogresult.ok; } }
Comments
Post a Comment