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; namespace WindowsFormsApp19 { public partial class Form11 : Form { public Form11() { InitializeComponent(); dateTimePicker1.Format = DateTimePickerFormat.Time; dateTimePicker1.ValueChanged += dateTimePicker1_ValueChanged; monthCalendar1.DateChanged += monthCalendar1_DateChanged; webBrowser1.Url = new Uri("http://google.com"); button1.Click += button1_Click; this.ShowInTaskbar = true; notifyIcon1.Click += notifyIcon1_Click; button1.Click += button1_Click; button2.Click += button2_Click; openFileDialog1.Filter = "Text files(*.txt)|*.txt|All files(*.*)|*.*"; saveFileDialog1.Filter = "Text files(*.txt)|*.txt|All files(*.*)|*.*"; button6.Click += button1_Click; // расширенное окно для выбора цвета colorDialog1.FullOpen = true; // установка начального цвета для colorDialog colorDialog1.Color = this.BackColor; } private void dateTimePicker1_ValueChanged(object sender, EventArgs e) { label1.Text = String.Format("Вы выбрали: {0}", dateTimePicker1.Value.ToLongTimeString()); } private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e) { label2.Text = String.Format("Вы выбрали: {0}", e.Start.ToLongDateString()); } private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { } private void textBox1_TextChanged(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { webBrowser1.Navigate(textBox1.Text); } private void notifyIcon1_DoubleClick(object sender, EventArgs e) { } private void notifyIcon1_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Normal; } private void button2_Click(object sender, EventArgs e) { MessageBox.Show( "Выберите один из вариантов", "Сообщение", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); } private void button3_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show( "Окрасить кнопку в красный цвет?", "Сообщение", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); if (result == DialogResult.Yes) button3.BackColor = Color.Red; this.TopMost = true; } private void button4_Click(object sender, EventArgs e) { if (saveFileDialog1.ShowDialog() == DialogResult.Cancel) return; // получаем выбранный файл string filename = saveFileDialog1.FileName; // сохраняем текст в файл System.IO.File.WriteAllText(filename, textBox1.Text); MessageBox.Show("Файл сохранен"); } private void button5_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.Cancel) return; // получаем выбранный файл string filename = openFileDialog1.FileName; // читаем файл в строку string fileText = System.IO.File.ReadAllText(filename); textBox1.Text = fileText; MessageBox.Show("Файл открыт"); } private void button6_Click(object sender, EventArgs e) { if (colorDialog1.ShowDialog() == DialogResult.Cancel) return; // установка цвета формы this.BackColor = colorDialog1.Color; } private void Form11_Load(object sender, EventArgs e) { nameBox.Validating += nameBox_Validating; ageBox.Validating += ageBox_Validating; } private void namebox_TextChanged(object sender, EventArgs e) { } private void nameBox_Validating(object sender, CancelEventArgs e) { if (String.IsNullOrEmpty(nameBox.Text)) { errorProvider1.SetError(nameBox, "Не указано имя!"); } else if (nameBox.Text.Length < 4) { errorProvider1.SetError(nameBox, "Слишком короткое имя!"); } else { errorProvider1.Clear(); } } private void ageBox_Validating(object sender, CancelEventArgs e) { int age = 0; if (String.IsNullOrEmpty(ageBox.Text)) { errorProvider1.SetError(ageBox, "Не указан возраст!"); } else if (!Int32.TryParse(ageBox.Text, out age)) { errorProvider1.SetError(ageBox, "Некорретный возраст!"); } else { errorProvider1.Clear(); } } } }