using ComponentsLibrary; using ComponentsView; namespace ComponentsLab { public partial class FormComponents : Form { private Random random = new Random(); public FormComponents() { InitializeComponent(); CreateImage(); EmailLoad(); } private void CreateImage() { Bitmap bmp = new(imageLoad.Width - 10, imageLoad.Height - 10); Graphics gr = Graphics.FromImage(bmp); gr.DrawEllipse(new Pen(Color.Red), 10, 10, 20, 20); imageLoad.Avatar = bmp; } private void ImageLoad_AvatarChanged(object sender, EventArgs e) { var width = imageLoad.Avatar.Width; MessageBox.Show($"Change avatar, width={width}"); } private void visualSelectionComponent1_ChangeComboBox(object sender, EventArgs e) { var val = visualSelectionComponent1.comboBoxSelectedValue; MessageBox.Show($"Change value, value={val}"); } private void EmailLoad() { emailComponent.EmailPattern = @"^[^@\s]+@[^@\s]+\.[^@\s]+$"; emailComponent.SetToolTip("Пример: example@domain.com"); } private void buttonCheckEmail_Click(object sender, EventArgs e) { try { var email = emailComponent.EmailValue; MessageBox.Show($"Email соответствует шаблону"); } catch (EmailException ex) { MessageBox.Show(ex.Message, "Ошибка. Веденный адрес электронной почты не соответствует шаблону. ", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void emailComponent_ChangeEmail(object sender, EventArgs e) { int r = random.Next(256); int g = random.Next(256); int b = random.Next(256); emailComponent.EmailTextBox.ForeColor = Color.FromArgb(r, g, b); } private void listBoxValues_Load(object sender, EventArgs e) { listBoxValues.SetLayout("Температура воздуха {T}, давление {P}", '{', '}'); var objectList = new List { new ObjectClass { T = 20.5, P = 1012 }, new ObjectClass { T = 18.3, P = 1008 }, new ObjectClass { T = 50.1, P = 1010 }, new ObjectClass { T = 30.0, P = 1011 }, new ObjectClass { T = 18.9, P = 1009 }, }; listBoxValues.FillListBox(objectList); } private void listBoxValues_GetObject(object sender, EventArgs e) { try { var selectedItem = listBoxValues.GetSelectedItem(); MessageBox.Show($"Объект создан: {selectedItem}"); } catch (EmailException ex) { MessageBox.Show(ex.Message, $"Ошибка при заполнении свойств объекта", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }