Добавил:
выбрасываю тут свой мусор, надеюсь, что он кому-то может пригодится... Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

laba2 работает и выглядит правильно

.docx
Скачиваний:
1
Добавлен:
03.12.2023
Размер:
26.6 Кб
Скачать

Код Form1.cs

using System;

using System.Windows.Forms;

using System.Globalization;

namespace WF2

{

public partial class Form1 : Form

{

Clock oclock = new Clock();

public Form1()

{

System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(Properties.Settings.Default.Language);

System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(Properties.Settings.Default.Language);

InitializeComponent();

oclock.SecondTick += ourTick;

}

void ourTick(object sender, EventArgs e)

{

textBox1.Text = "Дата:" + oclock.CityTime("Moscow").ToShortDateString() + " Время:" + oclock.CityTime("Moscow").ToLongTimeString();

textBox2.Text = "Дата:" + oclock.CityTime("Vladivostok").ToShortDateString() + " Время:" + oclock.CityTime("Vladivostok").ToLongTimeString();

textBox3.Text = "Дата:" + oclock.CityTime("London").ToShortDateString() + " Время:" + oclock.CityTime("London").ToLongTimeString();

}

private void ButtonStart(object sender, EventArgs e)

{

oclock.ChangeAct(true);

}

private void ButtonLanguage(object sender, EventArgs e)

{

if (System.Threading.Thread.CurrentThread.CurrentUICulture.Name == "ru")

{

System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en");

System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en");

Properties.Settings.Default.Language = "en";

Properties.Settings.Default.Save();

Application.Restart();

}

else

{

System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("ru");

System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("ru");

Properties.Settings.Default.Language = "ru";

Properties.Settings.Default.Save();

Application.Restart();

}

}

private void ButtonStop(object sender, EventArgs e)

{

oclock.ChangeAct(false);

}

private void ButtonStop_KeyDown(object sender, KeyEventArgs e)

{

if (e.KeyCode == Keys.S && e.Alt) //Alt+S для остановки

{

ButtonStop.PerformClick();

}

}

private void ButtonStart_KeyDown(object sender, KeyEventArgs e)

{

if (e.KeyCode == Keys.Enter && e.Alt) //Alt+S для старта

{

ButtonStart.PerformClick();

}

}

private void ButtonLanguage(object sender, KeyEventArgs e)

{

if (e.KeyCode == Keys.L && e.Alt) //Alt+L для смены языка

{

ButtonLanguage.PerformClick();

}

}

}

}

Код Class.cs

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace WF2

{

public class Clock

{

private Timer Timer = new Timer();

DateTime Date;

public delegate void getTime (object sender, EventArgs e);

public event getTime SecondTick;

public static Dictionary<string, TimeSpan> Dictionary = new Dictionary<string, TimeSpan>()//коллекция ключей и значений

{

{"Moscow", new TimeSpan(3, 0, 0)},

{"Vladivostok", new TimeSpan(10, 0, 0)},

{"London", new TimeSpan(1, 0, 0)}

};

public Clock()

{

Timer.Interval = 1000;

Timer.Enabled = false;

Timer.Tick += new EventHandler(Tick);// метод обрабатывающ событие, не имеющий данные

}

public void Tick(object sender, EventArgs e)

{

Date = DateTime.UtcNow;

SecondTick(sender, e);

}

public void ChangeAct(bool per)

{

Timer.Enabled = per;

}

public DateTime CityTime(string city)

{

return (Date + Dictionary[city]);

}

}

}

Код Program.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace WF2

{

static class Program

{

/// <summary>

/// Главная точка входа для приложения.

/// </summary>

[STAThread]

static void Main()

{

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new Form1());

}

}

}

Соседние файлы в предмете Объектно-ориентированное программирование