KOP-PIbd-32-Katysheva-N-E/ComponentsView/FormComponents.cs

100 lines
2.7 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("Òåìïåðàòóðà âîçäóõà {T}, äàâëåíèå {P}", '{', '}');
var objectList = new List<ObjectClass>
{
new ObjectClass { T = "òåìïåðàòóðà âûñîêàÿ", P = "1008" },
new ObjectClass { T = "òåìïåðàòóðà2", P = "1008" },
new ObjectClass { T = "òåìïåðàòóðà3", P = 1010 },
new ObjectClass { T = "òåìïåðàòóðà4", P = 1011 },
new ObjectClass { T = "òåìïåðàòóðà5", P = 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?.T;
object? P = obj?.P;
MessageBox.Show($"Îáúåêò ñîçäàí, ïåðâîå çíà÷åíèå: {T}, âòîðîå çíà÷åíèå: {P}");
}
}
}