Загрузка данных


namespace WinFormsApp17
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            listBox1.Items.AddRange(new string[] { "Круг", "Квадрат", "Треугольник", "Прямоугольник", "Ромб" });
        }

        private void label1_MouseClick(object sender, MouseEventArgs e)
        {
            label1.Text = DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss");
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            int selectionStart = textBox1.SelectionStart;
            textBox1.Text = textBox1.Text.ToUpper();
            textBox1.SelectionStart = selectionStart;
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (char.IsDigit(e.KeyChar))
            {
                e.Handled = true;
            }
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem != null)
            {
                label1.Text = listBox1.SelectedItem.ToString();
            }
        }

        private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            pictureBox1.BackColor = Color.LightGray;
        }

        private void pictureBox1_MouseLeave(object sender, EventArgs e)
        {
            pictureBox1.BackColor = SystemColors.Control;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string content = textBox1.Text;
                string fileName = "журнал_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".txt";
                string filePath = Path.Combine(Application.StartupPath, fileName);

                File.WriteAllText(filePath, content);
                label1.Text = "Файл сохранён";
            }
            catch (UnauthorizedAccessException)
            {
                MessageBox.Show("Ошибка: Нет прав для записи в эту папку.", "Доступ запрещен", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (IOException ex)
            {
                MessageBox.Show($"Ошибка при записи файла: {ex.Message}", "Ошибка ввода-вывода", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Непредвиденная ошибка: {ex.Message}", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}