Uploaded by Кот Щавель

bilet10

advertisement
using System;
using System.Windows.Forms;
namespace WindowsFormsApp
{
public partial class MainForm : Form
{
private TextBox surnameTextBox;
private TextBox firstNameTextBox;
private TextBox middleNameTextBox;
private TextBox birthYearTextBox;
private CheckBox middleNameCheckBox;
private Button processButton;
public MainForm()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.surnameTextBox = new TextBox();
this.firstNameTextBox = new TextBox();
this.middleNameTextBox = new TextBox();
this.birthYearTextBox = new TextBox();
this.middleNameCheckBox = new CheckBox();
this.processButton = new Button();
this.SuspendLayout();
// Surname label
var surnameLabel = new Label();
surnameLabel.Text = "Фамилия:";
surnameLabel.Location = new System.Drawing.Point(20, 20);
surnameLabel.AutoSize = true;
this.Controls.Add(surnameLabel);
// Surname textbox
this.surnameTextBox.Location = new System.Drawing.Point(150, 20);
this.surnameTextBox.Size = new System.Drawing.Size(200, 20);
this.Controls.Add(this.surnameTextBox);
// First name label
var firstNameLabel = new Label();
firstNameLabel.Text = "Имя:";
firstNameLabel.Location = new System.Drawing.Point(20, 60);
firstNameLabel.AutoSize = true;
this.Controls.Add(firstNameLabel);
// First name textbox
this.firstNameTextBox.Location = new System.Drawing.Point(150, 60);
this.firstNameTextBox.Size = new System.Drawing.Size(200, 20);
this.Controls.Add(this.firstNameTextBox);
// Middle name label
var middleNameLabel = new Label();
middleNameLabel.Text = "Отчество:";
middleNameLabel.Location = new System.Drawing.Point(20, 100);
middleNameLabel.AutoSize = true;
this.Controls.Add(middleNameLabel);
// Middle name textbox
this.middleNameTextBox.Location = new System.Drawing.Point(150, 100);
this.middleNameTextBox.Size = new System.Drawing.Size(200, 20);
this.middleNameTextBox.Enabled = false;
this.Controls.Add(this.middleNameTextBox);
// Middle name checkbox
this.middleNameCheckBox.Text = "Отчество присутствует";
this.middleNameCheckBox.Location = new System.Drawing.Point(150, 130);
this.middleNameCheckBox.AutoSize = true;
this.middleNameCheckBox.CheckedChanged += MiddleNameCheckBox_CheckedChanged;
this.Controls.Add(this.middleNameCheckBox);
// Birth year label
var birthYearLabel = new Label();
birthYearLabel.Text = "Год рождения:";
birthYearLabel.Location = new System.Drawing.Point(20, 170);
birthYearLabel.AutoSize = true;
this.Controls.Add(birthYearLabel);
// Birth year textbox
this.birthYearTextBox.Location = new System.Drawing.Point(150, 170);
this.birthYearTextBox.Size = new System.Drawing.Size(200, 20);
this.Controls.Add(this.birthYearTextBox);
// Process button
this.processButton.Text = "Обработать";
this.processButton.Location = new System.Drawing.Point(150, 220);
this.processButton.Size = new System.Drawing.Size(100, 30);
this.processButton.Click += ProcessButton_Click;
this.Controls.Add(this.processButton);
// Main form
this.ClientSize = new System.Drawing.Size(400, 280);
this.Text = "Приветствие";
this.ResumeLayout(false);
this.PerformLayout();
}
private void MiddleNameCheckBox_CheckedChanged(object sender, EventArgs e)
{
this.middleNameTextBox.Enabled = this.middleNameCheckBox.Checked;
}
private void ProcessButton_Click(object sender, EventArgs e)
{
string surname = this.surnameTextBox.Text;
string firstName = this.firstNameTextBox.Text;
string middleName = this.middleNameTextBox.Enabled ? this.middleNameTextBox.Text : "";
string birthYear = this.birthYearTextBox.Text;
if (string.IsNullOrEmpty(surname) || string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(birthYear))
{
MessageBox.Show("Неопознанная форма жизни");
}
else
{
string greeting = $"Приветствую тебя, о Великий {surname} {firstName} {middleName}, {birthYear}-ого года рождения!";
MessageBox.Show(greeting);
}
}
}
public static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
}
Download