PIbd-31_MasenkinMS_COP_22/Components/WinForms/FormComponents.cs
2024-09-05 18:58:41 +04:00

135 lines
4.3 KiB
C#

namespace WinForms
{
/// <summary>
/// Îñíîâíàÿ ôîðìà
/// </summary>
public partial class FormComponents : Form
{
/// <summary>
/// Êîíñòðóêòîð
/// </summary>
public FormComponents()
{
InitializeComponent();
customComboBox.AddItem("Ýëåìåíò 1");
customComboBox.AddItem("Ýëåìåíò 2");
customComboBox.AddItem("Ýëåìåíò 3");
customTextBox.DatePattern = @"^(\d{2}.\d{2}.\d{4})$";
customListBox.SetLayoutInfo("Èìÿ *Name* Ôàìèëèÿ *Surname*", "*", "*");
}
/// <summary>
/// Äîáàâèòü ýäåìåíòû â customComboBox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonAddItems_Click(object sender, EventArgs e)
{
customComboBox.AddItem("Ýëåìåíò 3");
customComboBox.AddItem("Ýëåìåíò 4");
customComboBox.AddItem("Ýëåìåíò 5");
}
/// <summary>
/// Î÷èñòèòü ñïèñîê ýëåìåíòîâ customComboBox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonClearItems_Click(object sender, EventArgs e)
{
customComboBox.Clear();
}
/// <summary>
/// Ïîëó÷èòü âûáðàííûé ýëåìåíò èç customComboBox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonGetItem_Click(object sender, EventArgs e)
{
labelItem.Text = customComboBox.SelectedItem.ToString();
}
/// <summary>
/// Ïðîâåðêà ââåäåííîãî çíà÷åíèÿ ñ çàäàííûì øàáëîíîì customTextBox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonValidate_Click(object sender, EventArgs e)
{
try
{
if (customTextBox.TextBoxValue != null)
{
checkBoxValidate.Text = "Ïîäõîäèò";
checkBoxValidate.Checked = true;
checkBoxValidate.BackColor = Color.LightGreen;
}
}
catch (Exception ex)
{
checkBoxValidate.Text = "Íå ïîäõîäèò";
checkBoxValidate.Checked = false;
checkBoxValidate.BackColor = Color.Red;
MessageBox.Show(ex.Message);
}
}
/// <summary>
/// Èçìåíèòü ïðèìåð çàäàííîãî øàáëîíà customTextBox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonSetDateExample_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxDateExample.Text))
{
return;
}
if (customTextBox.SetDateExample(textBoxDateExample.Text))
{
MessageBox.Show("Ïðèìåð çàäàííîãî øàáëîíà óñïåøíî èçìåí¸í!", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Ïðèìåð çàäàííîãî øàáëîíà íå ïîäõîäèò!", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// Äîáàâèòü îáúåêòû â customListBox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonAddObjects_Click(object sender, EventArgs e)
{
customListBox.AddObject<Person>(new Person("Åâãåíèé", "Ýãîâ"));
customListBox.AddObject<Person>(new Person("Àíòîí", "Ñêàëêèí"));
customListBox.AddObject<Person>(new Person("Ìàêñèì", "Ìàñåíüêèí"));
}
/// <summary>
/// Ïîëó÷èòü îáúåêò èç customListBox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonGetObject_Click(object sender, EventArgs e)
{
Person person = customListBox.GetObject<Person>();
if (person == null)
{
labelObjectInfo.Text = "Îáúåêò íå íàéäåí";
return;
}
string objectInfo = person.Name + " " + person.Surname;
labelObjectInfo.Text = objectInfo;
}
}
}