C# 在C语言上编程可怕的尖叫者#
我是c#新手,正在尝试开发吓人的尖叫器应用程序。这是一个windows窗体应用程序,它在PC上运行,在任务栏中不可见。 此应用程序中正在运行计时器。如果系统datetime.now.minute=15 它应该播放可怕的声音,并在屏幕上显示可怕的图片。1-2秒后,画面应从屏幕上消失。 但我被困住了,不知道如何让照片消失。有什么办法吗? 下面是我的代码:C# 在C语言上编程可怕的尖叫者#,c#,winforms,C#,Winforms,我是c#新手,正在尝试开发吓人的尖叫器应用程序。这是一个windows窗体应用程序,它在PC上运行,在任务栏中不可见。 此应用程序中正在运行计时器。如果系统datetime.now.minute=15 它应该播放可怕的声音,并在屏幕上显示可怕的图片。1-2秒后,画面应从屏幕上消失。 但我被困住了,不知道如何让照片消失。有什么办法吗? 下面是我的代码: namespace screamer2 { public partial class Form1 : Form {
namespace screamer2
{
public partial class Form1 : Form
{
SoundPlayer pla = new SoundPlayer(Properties.Resources._3);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.TransparencyKey = this.BackColor;
this.Left = 0;
this.Top = 0;
this.Width = Screen.PrimaryScreen.Bounds.Width/2;
this.Height = Screen.PrimaryScreen.Bounds.Height/2;
this.TopMost = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (DateTime.Now.Minute == 15)
{
BackgroundImage = Properties.Resources._1;
System.Threading.Thread.Sleep(500);
pla.Play();
}
}
}
}
我建议在
Form1\u Load
中设置一次图像,然后使用Form.Opacity
变量控制窗口的任何显示和隐藏。我已经测试了下面的代码,应该可以按照您的要求工作
SoundPlayer pla = new SoundPlayer(Properties.Resources._3);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.TransparencyKey = this.BackColor;
this.Left = 0;
this.Top = 0;
this.Opacity = 0; //This line added
this.Width = Screen.PrimaryScreen.Bounds.Width / 2;
this.Height = Screen.PrimaryScreen.Bounds.Height / 2;
this.BackgroundImage = Properties.Resources._1; //We set the image once here
this.TopMost = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (DateTime.Now.Minute == 15)
{
this.Opacity = 1; //We show the window
System.Threading.Thread.Sleep(500);
pla.Play();
this.Opacity = 0; //We hide the window
}
}
您是否尝试过
BackgroundImage=null代码>?播放声音并等待后,将背景图像设置回Null?我已经尝试过了,但如果我这样做了,那么图片就根本不出现。@Nikolai你是在线程后将背景图像设置回Null吗?睡眠?你知道我们都不知道什么是“可怕的尖叫者”因此,把它放在你的问题标题没有增加价值吗?