135 lines
4.3 KiB
C#
135 lines
4.3 KiB
C#
namespace WinForms
|
|
{
|
|
/// <summary>
|
|
/// Ôîðìà äëÿ âèçóàëüíûõ êîìïîíåíòîâ
|
|
/// </summary>
|
|
public partial class FormVisualComponents : Form
|
|
{
|
|
/// <summary>
|
|
/// Êîíñòðóêòîð
|
|
/// </summary>
|
|
public FormVisualComponents()
|
|
{
|
|
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)
|
|
{
|
|
Employee person = customListBox.GetObject<Employee>();
|
|
if (person == null)
|
|
{
|
|
labelObjectInfo.Text = "Îáúåêò íå íàéäåí";
|
|
return;
|
|
}
|
|
|
|
string objectInfo = person.Name + " " + person.Surname;
|
|
labelObjectInfo.Text = objectInfo;
|
|
}
|
|
}
|
|
}
|