Хелпикс

Главная

Контакты

Случайная статья





AlarmClock



using System;

usingSystem. Collections. Generic;

usingSystem. ComponentModel;

usingSystem. Data;

usingSystem. Drawing;

usingSystem. Linq;

usingSystem. Text;

usingSystem. Windows. Forms;

 

namespace WindowsFormsApplication1

{

publicpartialclassForm1: Form

{

// функция PlaySound, обеспечивающая воспроизведение

// wav-файлов, находится в библиотеке winmm. dll

// подключим эту библиотеку

   [System. Runtime. InteropServices. DllImport(" winmm. dll" )]

privatestaticextern

BooleanPlaySound(stringlpszName, inthModule, intdwFlags);

 

// время сигнала (отображения сообщения)

privateDateTime alarm;

 

public Form1()

   {

InitializeComponent();

// параметрыкомпонентовnumericUpDown

       numericUpDown1. Maximum = 23;

       numericUpDown1. Minimum = 0;

 

       numericUpDown2. Maximum = 59;

       numericUpDown2. Minimum = 0;

 

       numericUpDown1. Value = DateTime. Now. Hour;

       numericUpDown2. Value = DateTime. Now. Minute;

 

notifyIcon1. Visible = false;

 

// период обработки сигнала от таймера

timer1. Interval = 1000;

       timer1. Enabled = true;

 

       label2. Text = DateTime. Now. ToLongTimeString();            

   }

 

privatevoid timer1_Tick(object sender, EventArgs e)

   {

       label2. Text = DateTime. Now. ToLongTimeString();

 

// будильник установлен

if (checkBox1. Checked)

       {

// время срабатывания будильника

if (DateTime. Compare(DateTime. Now, alarm) > 0)

           {

               checkBox1. Checked = false;

 

PlaySound(Application. StartupPath +

" \\ring. wav", 0, 1);

 

 

Form2frm = newForm2();

// чтобы получить доступ к компонентам формы frm (Form2),

// их надо объявить как public (см. Form2. Designer. cs)

               frm. label1. Text = DateTime. Now. ToShortTimeString();

               frm. label2. Text = this. textBox1. Text;

frm. ShowDialog();

 

this. Show();

           }

       }

   }

 

privatevoid checkBox1_CheckedChanged(object sender, EventArgs e)

   {

if (checkBox1. Checked)

       {

           numericUpDown1. Enabled = false;

           numericUpDown2. Enabled = false;

 

// установитьвремясигнала

alarm = newDateTime(

DateTime. Now. Year,

DateTime. Now. Month,

DateTime. Now. Day,

Convert. ToInt16(numericUpDown1. Value),

Convert. ToInt16(numericUpDown2. Value),

0, 0);

 

// если установленное время будильника меньше

// текущего, нужно увеличить дату срабатывания

// на единицу (+1 день)

if (DateTime. Compare(DateTime. Now, alarm) > 0)

alarm = alarm. AddDays(1);

 

           notifyIcon1. Text = alarm. ToShortTimeString() + " \n" + textBox1. Text;

 

           button1. Enabled = true;

       }

else

       {

           numericUpDown1. Enabled = true;

           numericUpDown2. Enabled = true;

 

           notifyIcon1. Text =

" Будильник не установлен";

 

           button1. Enabled = false;

}

   }

 

privatevoid button1_Click(object sender, EventArgs e)

   {

this. Hide();

       notifyIcon1. Visible = true;

}

 

// выбор в контекстном меню команды Показать/Свернуть

privatevoid toolStripMenuItem1_Click(object sender, EventArgs e)

   {

if (this. Visible)

       {

this. Hide();

       }

 

else

       {

this. Show();

           notifyIcon1. Visible = false;

       }

   }

 

// опрограмме

privatevoid toolStripMenuItem2_Click(object sender, EventArgs e)

{

 

   }

 

// выбор в контекстном меню команды Завершить

privatevoid toolStripMenuItem3_Click(object sender, EventArgs e)

{

this. Close();

   }

}

}

 



  

© helpiks.su При использовании или копировании материалов прямая ссылка на сайт обязательна.