KOP-PIbd-32-Katysheva-N-E/ComponentsView/FormComponents.cs
2024-10-10 16:57:14 +03:00

96 lines
2.8 KiB
C#

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("Òåìïåðàòóðà âîçäóõà [Temp], äàâëåíèå [Pressure]", '[', ']');
var objectList = new List<ObjectClass>
{
new ObjectClass { Temp = "òåìïåðàòóðà âûñîêàÿ", Pressure = "1008" },
new ObjectClass { Temp = "òåìïåðàòóðà2", Pressure = "1008" },
new ObjectClass { Temp = "òåìïåðàòóðà3", Pressure = 1010 },
new ObjectClass { Temp = "òåìïåðàòóðà4", Pressure = 1011 },
new ObjectClass { Temp = "òåìïåðàòóðà5", Pressure = 1009 },
};
listBoxValues.FillListBox(objectList);
}
private void listBoxValues_GetObject(object sender, EventArgs e)
{
try
{
var selectedItem = listBoxValues.GetSelectedItem<ObjectClass>();
checkParametrs();
}
catch (EmailException ex)
{
MessageBox.Show(ex.Message, $"Îøèáêà ïðè çàïîëíåíèè ñâîéñòâ îáúåêòà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void checkParametrs()
{
ObjectClass obj = listBoxValues.GetSelectedItem<ObjectClass>();
object? T = obj?.Temp;
object? P = obj?.Pressure;
MessageBox.Show($"Îáúåêò ñîçäàí, ïåðâîå çíà÷åíèå: {T}, âòîðîå çíà÷åíèå: {P}");
}
}
}