-1

I am new in c# and trying to develop Scary Screamer Application. It is an joke windows forms application which is running on the PC and invisible in taskbar. There is timer running in this application. If system datetime.now.minute = 15 It should play scary sound and show scary picture on the screen. After 1-2 seconds picture should disappear from the screen. But i am stuck and don't know how to make picture disappear. Any Ideas how to do that? Below is my code:

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();
            }
        }
    }
}
Guy Levy
  • 1,550
  • 2
  • 15
  • 26

1 Answers1

1

I would propose to set image once in Form1_Load and then control any showing and hiding of window using Form.Opacity variable. I have tested the code below and should work as you wanted.

 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
        }
    }
pajamac
  • 113
  • 13