PIbd-31_Afanasev.S.S._COP_5/Component/Forms/Form.cs

98 lines
3.0 KiB
C#

using ComponentProgramming;
namespace Forms
{
public partial class Form : System.Windows.Forms.Form
{
private bool _isFormLoaded = false;
public Form()
{
InitializeComponent();
FillBox();
FillTextBox();
FillGrid();
// Óñòàíàâëèâàåì ôëàã ïîñëå çàâåðøåíèÿ èíèöèàëèçàöèè
_isFormLoaded = true;
}
private void FillBox()
{
List<string> items = new List<string> { "Çíà÷åíèå 1", "Çíà÷åíèå 2", "Çíà÷åíèå 3", "Çíà÷åíèå 4" };
controlListBox.FillListBox(items);
}
private void FillTextBox()
{
controlTextBox.NumPattern = @"^\d+$";
controlTextBox.IntegerValue = 5;
}
private void FillGrid()
{
List<string> headers = new List<string>() { "Id", "Èìÿ", "Ôàìèëèÿ" };
List<int> width = new List<int>() { 100, 200, 200 };
List<bool> isVisible = new List<bool>() { true, true, true };
List<string> props = new List<string>() { "Id", "Name", "Surname" };
controlDataGrid.CreateColumns(3, headers, width, isVisible, props);
// Ïåðåäàåì ñïèñîê îáúåêòîâ
List<Person> people = new List<Person>
{
new Person(1, "Àëåêñàíäð", "Ïåòðîâ"),
new Person(2, "Âëàäèìèð", "Êóçüìèí")
};
controlDataGrid.FillDataGrid(people);
}
private void controlListBox_ListBoxChanged(object sender, EventArgs e)
{
if (_isFormLoaded) // Ïðîâåðÿåì, ÷òî ôîðìà çàãðóæåíà
{
var elem = controlListBox.SelectedItem;
MessageBox.Show($"Âûáðàíî: {elem}");
}
}
private void controlTextBox_CheckBoxChanged(object sender, EventArgs e)
{
if (_isFormLoaded) // Ïðîâåðÿåì, ÷òî ôîðìà çàãðóæåíà
{
if (controlTextBox.IntegerValue == null)
{
MessageBox.Show($"CheckBox îòìå÷åí");
}
else
{
MessageBox.Show($"CheckBox íå îòìå÷åí");
}
}
}
private void buttonGetObj_Click(object sender, EventArgs e)
{
var val = controlDataGrid.GetObject<Person>();
MessageBox.Show($"{val?.Name} {val?.Surname}");
}
private void buttonClear_Click(object sender, EventArgs e)
{
controlDataGrid.ClearData();
}
private void buttonEnter_Click(object sender, EventArgs e)
{
var val = controlTextBox.IntegerValue;
MessageBox.Show($"Ââåäåíî {val}");
}
private void buttonAdd_Click(object sender, EventArgs e)
{
controlDataGrid.SetData<Person>(new Person(1, "Àëåêñàíäð", "Ïåòðîâ"), 2);
controlDataGrid.SetData<Person>(new Person(2, "Ñòåïàí", "Ïåòðîâ"), 2);
}
}
}