Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Threading;
- namespace Alarm
- {
- public partial class MainForm : Form
- {
- private Thread _clockThread;
- private bool _clockWork;
- //private DateTime _time;
- private Clock _cl;
- private delegate void SetLabel(string str);
- private delegate void ShowForm();
- public MainForm()
- {
- InitializeComponent();
- try
- {
- //_time = DateTime.Now;
- _cl = new Clock();
- _clockWork = true;
- _clockThread = new Thread(ShowTime);
- _clockThread.Start();
- }
- catch (Exception ex)
- {
- System.Windows.Forms.Application.Exit();
- }
- }
- AlarmForm af;
- private void SetLabelTime(string time)
- {
- labelTime.Text = time;
- if(_cl.AlarmEnable)
- {
- toolStripAlarmTime.Text = _cl.GetAlarmTime;
- toolStripAlarmStatus.Text = "Включен";
- }
- else
- {
- toolStripAlarmTime.Text = "";
- toolStripAlarmStatus.Text = "Выключен";
- }
- toolStripStatusLabel1.Text = "Текущее время " + _cl.GetTime;
- }
- private void ShowAlarmForm()
- {
- af = new AlarmForm();
- af.Owner = this;
- af.StartPosition = FormStartPosition.CenterParent;
- af.ShowDialog(this);
- }
- private void ShowTime()
- {
- string time;
- while (_clockWork)
- {
- //_time.AddTicks(1);
- //DateTime.
- time = _cl.GetTime;
- if (this.InvokeRequired)
- {
- this.Invoke(new SetLabel(SetLabelTime), time);
- }
- else
- {
- SetLabelTime(time);
- }
- if(_cl.AlarmSignal)
- {
- _cl.AlarmOff();
- this.BeginInvoke(new ShowForm(ShowAlarmForm), null);
- }
- Thread.Sleep(500);
- }
- }
- private void MainForm_Load(object sender, EventArgs e)
- {
- }
- private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
- {
- _clockWork = false;
- _clockThread.Abort();
- _clockThread.Join(10000);
- }
- private void toolStripMenuItem1_Click(object sender, EventArgs e)
- {
- }
- private void toolStripMenuItem5_Click_1(object sender, EventArgs e)
- {
- this.Close();
- }
- private void показатьToolStripMenuItem_Click(object sender, EventArgs e)
- {
- labelTime.Visible = true;
- SetPosForm spf = new SetPosForm(this.Size.Width, this.Size.Height);
- spf.Owner = this;
- spf.StartPosition = FormStartPosition.CenterParent;
- if(spf.ShowDialog(this) == DialogResult.OK)
- {
- labelTime.Left = spf.PosX ;
- labelTime.Top = spf.PosY + 23;
- }
- }
- private void скрытьToolStripMenuItem_Click(object sender, EventArgs e)
- {
- labelTime.Visible = false;
- }
- private void установитьВремяToolStripMenuItem_Click(object sender, EventArgs e)
- {
- try
- {
- SetTimeForm tf = new SetTimeForm(_cl.Value);
- tf.Owner = this;
- tf.StartPosition = FormStartPosition.CenterParent;
- if (tf.ShowDialog(this) == DialogResult.OK)
- {
- _cl.Value = tf.NewDate;
- }
- }
- catch(Exception ex)
- {
- }
- }
- private void установитьВремяToolStripMenuItem1_Click(object sender, EventArgs e)
- {
- try
- {
- SetTimeForm tf = new SetTimeForm(_cl.Value);
- tf.Owner = this;
- tf.StartPosition = FormStartPosition.CenterParent;
- if (tf.ShowDialog(this) == DialogResult.OK)
- {
- _cl.AlarmOn(tf.NewDate);
- }
- }
- catch (Exception ex)
- {
- }
- }
- private void toolStripStatusLabel1_Click(object sender, EventArgs e)
- {
- }
- private void выключитьToolStripMenuItem_Click(object sender, EventArgs e)
- {
- _cl.AlarmOff();
- }
- private void включитьToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (!_cl.AlarmInstall)
- this.установитьВремяToolStripMenuItem1_Click(sender, e);
- _cl.AlarmOn();
- }
- private void инструкцияToolStripMenuItem_Click(object sender, EventArgs e)
- {
- TextForm tf = new TextForm("ИНСТРУКЦИЯ и прочие бла бла бла вставляются сюда текстом. В эту строку!");
- tf.Owner = this;
- tf.StartPosition = FormStartPosition.CenterParent;
- tf.ShowDialog();
- }
- private void оПрограммеToolStripMenuItem_Click(object sender, EventArgs e)
- {
- TextForm tf = new TextForm("О программе и прочие бла бла бла вставляются сюда текстом. В эту строку!");
- tf.Owner = this;
- tf.StartPosition = FormStartPosition.CenterParent;
- tf.ShowDialog();
- }
- private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment