使用Winforms非常容易.您需要一个带有灰色背景的无边框最大化窗口,其中的Opacity随计时器而变化.淡入淡出完成后,您可以显示无边框的对话框,并使用TransparencyKey使其背景透明.这是一个实现这个的示例主表单:
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 the overlay
using (var overlay = new Form2()) {
overlay.ShowDialog(this);
this.Close();
}
}
}
Timer fadeTimer;
}
Run Code Online (Sandbox Code Playgroud)
对话框:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2594 次 |
| 最近记录: |