diff --git a/YunusovComponentsLibrary/Form1/Form1.Designer.cs b/YunusovComponentsLibrary/Form1/Form1.Designer.cs new file mode 100644 index 0000000..99a5c61 --- /dev/null +++ b/YunusovComponentsLibrary/Form1/Form1.Designer.cs @@ -0,0 +1,222 @@ +namespace Form1 +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + selectComponent = new YunusovComponentsLibrary.SelectedComponent(); + groupBoxSelect = new GroupBox(); + buttonGetSelected = new Button(); + buttonClear = new Button(); + textBox = new TextBox(); + buttonAdd = new Button(); + inputComponent = new YunusovComponentsLibrary.InputComponent(); + groupBoxInput = new GroupBox(); + buttonShowFloat = new Button(); + groupBoxListOutput = new GroupBox(); + buttonGetListOutput = new Button(); + buttonAddListOutput = new Button(); + buttonClearListOutput = new Button(); + listOutputComponent = new YunusovComponentsLibrary.ListOutputComponent(); + groupBoxSelect.SuspendLayout(); + groupBoxInput.SuspendLayout(); + groupBoxListOutput.SuspendLayout(); + SuspendLayout(); + // + // selectComponent + // + selectComponent.Location = new Point(6, 32); + selectComponent.Name = "selectComponent"; + selectComponent.SelectedItem = ""; + selectComponent.Size = new Size(164, 226); + selectComponent.TabIndex = 0; + // + // groupBoxSelect + // + groupBoxSelect.Controls.Add(buttonGetSelected); + groupBoxSelect.Controls.Add(buttonClear); + groupBoxSelect.Controls.Add(textBox); + groupBoxSelect.Controls.Add(buttonAdd); + groupBoxSelect.Controls.Add(selectComponent); + groupBoxSelect.Location = new Point(12, 1); + groupBoxSelect.Name = "groupBoxSelect"; + groupBoxSelect.Size = new Size(302, 241); + groupBoxSelect.TabIndex = 1; + groupBoxSelect.TabStop = false; + groupBoxSelect.Text = "Selected"; + // + // buttonGetSelected + // + buttonGetSelected.Location = new Point(171, 192); + buttonGetSelected.Name = "buttonGetSelected"; + buttonGetSelected.Size = new Size(125, 29); + buttonGetSelected.TabIndex = 4; + buttonGetSelected.Text = "Get selected"; + buttonGetSelected.UseVisualStyleBackColor = true; + buttonGetSelected.Click += SelectComponent_ItemSelected; + // + // buttonClear + // + buttonClear.Location = new Point(171, 140); + buttonClear.Name = "buttonClear"; + buttonClear.Size = new Size(125, 29); + buttonClear.TabIndex = 3; + buttonClear.Text = "Clear"; + buttonClear.UseVisualStyleBackColor = true; + buttonClear.Click += buttonClearList_Click; + // + // textBox + // + textBox.Location = new Point(171, 41); + textBox.Name = "textBox"; + textBox.Size = new Size(125, 27); + textBox.TabIndex = 2; + // + // buttonAdd + // + buttonAdd.Location = new Point(171, 92); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(125, 29); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Add"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // inputComponent + // + inputComponent.Location = new Point(6, 26); + inputComponent.Name = "inputComponent"; + inputComponent.Size = new Size(181, 49); + inputComponent.TabIndex = 2; + // + // groupBoxInput + // + groupBoxInput.Controls.Add(buttonShowFloat); + groupBoxInput.Controls.Add(inputComponent); + groupBoxInput.Location = new Point(360, 1); + groupBoxInput.Name = "groupBoxInput"; + groupBoxInput.Size = new Size(190, 241); + groupBoxInput.TabIndex = 3; + groupBoxInput.TabStop = false; + groupBoxInput.Text = "Input"; + // + // buttonShowFloat + // + buttonShowFloat.Location = new Point(45, 81); + buttonShowFloat.Name = "buttonShowFloat"; + buttonShowFloat.Size = new Size(94, 29); + buttonShowFloat.TabIndex = 4; + buttonShowFloat.Text = "Show"; + buttonShowFloat.UseVisualStyleBackColor = true; + buttonShowFloat.Click += buttonShowFloat_Click; + // + // groupBoxListOutput + // + groupBoxListOutput.Controls.Add(buttonGetListOutput); + groupBoxListOutput.Controls.Add(buttonAddListOutput); + groupBoxListOutput.Controls.Add(buttonClearListOutput); + groupBoxListOutput.Controls.Add(listOutputComponent); + groupBoxListOutput.Location = new Point(592, 1); + groupBoxListOutput.Name = "groupBoxListOutput"; + groupBoxListOutput.Size = new Size(570, 241); + groupBoxListOutput.TabIndex = 4; + groupBoxListOutput.TabStop = false; + groupBoxListOutput.Text = "ListOutput"; + // + // buttonGetListOutput + // + buttonGetListOutput.Location = new Point(457, 143); + buttonGetListOutput.Name = "buttonGetListOutput"; + buttonGetListOutput.Size = new Size(94, 29); + buttonGetListOutput.TabIndex = 7; + buttonGetListOutput.Text = "Get"; + buttonGetListOutput.UseVisualStyleBackColor = true; + buttonGetListOutput.Click += buttonGetListOutput_Click; + // + // buttonAddListOutput + // + buttonAddListOutput.Location = new Point(457, 26); + buttonAddListOutput.Name = "buttonAddListOutput"; + buttonAddListOutput.Size = new Size(94, 29); + buttonAddListOutput.TabIndex = 6; + buttonAddListOutput.Text = "Add"; + buttonAddListOutput.UseVisualStyleBackColor = true; + buttonAddListOutput.Click += buttonAddListOutput_Click; + // + // buttonClearListOutput + // + buttonClearListOutput.Location = new Point(457, 81); + buttonClearListOutput.Name = "buttonClearListOutput"; + buttonClearListOutput.Size = new Size(94, 29); + buttonClearListOutput.TabIndex = 5; + buttonClearListOutput.Text = "Clear"; + buttonClearListOutput.UseVisualStyleBackColor = true; + buttonClearListOutput.Click += buttonClearListOutput_Click; + // + // listOutputComponent + // + listOutputComponent.Location = new Point(6, 26); + listOutputComponent.Name = "listOutputComponent"; + listOutputComponent.SelectedRow = -1; + listOutputComponent.Size = new Size(414, 204); + listOutputComponent.TabIndex = 0; + // + // Form1 + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1174, 641); + Controls.Add(groupBoxListOutput); + Controls.Add(groupBoxInput); + Controls.Add(groupBoxSelect); + Name = "Form1"; + Text = "Form1"; + groupBoxSelect.ResumeLayout(false); + groupBoxSelect.PerformLayout(); + groupBoxInput.ResumeLayout(false); + groupBoxListOutput.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private YunusovComponentsLibrary.SelectedComponent selectComponent; + private GroupBox groupBoxSelect; + private Button buttonGetSelected; + private Button buttonClear; + private TextBox textBox; + private Button buttonAdd; + private YunusovComponentsLibrary.InputComponent inputComponent; + private GroupBox groupBoxInput; + private Button buttonShowFloat; + private GroupBox groupBoxListOutput; + private YunusovComponentsLibrary.ListOutputComponent listOutputComponent; + private Button buttonGetListOutput; + private Button buttonAddListOutput; + private Button buttonClearListOutput; + } +} \ No newline at end of file diff --git a/YunusovComponentsLibrary/Form1/Form1.cs b/YunusovComponentsLibrary/Form1/Form1.cs new file mode 100644 index 0000000..b1a3a68 --- /dev/null +++ b/YunusovComponentsLibrary/Form1/Form1.cs @@ -0,0 +1,107 @@ +using System.Windows.Forms; +using YunusovComponentsLibrary; +using YunusovComponentsLibrary.Exceptions; + +namespace Form1 +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + + + InitializeSelectComponent(); + InitializeInputComponent(); + + } + private void InitializeSelectComponent() + { + selectComponent.Input(" 1"); + selectComponent.Input(" 2"); + selectComponent.Input(" 3"); + selectComponent.Input(" 4"); + selectComponent.Input(" 5"); + } + private void SelectComponent_ItemSelected(object sender, EventArgs e) + { + MessageBox.Show(selectComponent.SelectedItem); + } + private void buttonAdd_Click(object sender, EventArgs e) + { + if (textBox.Text != "") + selectComponent.Input(textBox.Text); + } + private void buttonClearList_Click(object sender, EventArgs e) + { + selectComponent.ClearList(); + } + private void InitializeInputComponent() + { + inputComponent.FloatValue = 12.3f; + } + private void buttonShowFloat_Click(object sender, EventArgs e) + { + try + { + float? Value = inputComponent.FloatValue; + if (Value != null) + { + MessageBox.Show($" : {Value}"); + } + else + { + MessageBox.Show(" - null"); + } + } + catch (NotFloatException ex) + { + MessageBox.Show(ex.Message); + } + catch (EmptyValueException ex) + { + MessageBox.Show(ex.Message); + } + } + private void InitializeDataGridViewComponent() + { + listOutputComponent.ConfigColumn(new() + { + ColumnsCount = 4, + Header = new string[] { "ID", "", "", "" }, + Width = new int[] { 10, 150, 150, 100 }, + IsVisible = new bool[] { false, true, true, true }, + PropertiesName = new string[] { "Id", "Name", "Yourname", "Age" } + }); + List Persons = new() + { + new TestPerson(1, "", "", 20), + new TestPerson(2, "", "", 20), + new TestPerson(3, "", "", 59), + new TestPerson(4, "", "", 25), + new TestPerson(5, "", "", 89), + }; + + foreach (TestPerson person in Persons) + { + listOutputComponent.AddItem(person); + } + } + + private void buttonAddListOutput_Click(object sender, EventArgs e) + { + InitializeDataGridViewComponent(); + } + + private void buttonClearListOutput_Click(object sender, EventArgs e) + { + listOutputComponent.ClearDataGridView(); + } + + private void buttonGetListOutput_Click(object sender, EventArgs e) + { + var Test = listOutputComponent.GetSelectedObject(); + MessageBox.Show(Test.ToString()); + } + } +} \ No newline at end of file diff --git a/YunusovComponentsLibrary/Form1/Form1.csproj b/YunusovComponentsLibrary/Form1/Form1.csproj new file mode 100644 index 0000000..f4067ca --- /dev/null +++ b/YunusovComponentsLibrary/Form1/Form1.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + \ No newline at end of file diff --git a/YunusovComponentsLibrary/Form1/Form1.resx b/YunusovComponentsLibrary/Form1/Form1.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/YunusovComponentsLibrary/Form1/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/YunusovComponentsLibrary/Form1/Program.cs b/YunusovComponentsLibrary/Form1/Program.cs new file mode 100644 index 0000000..b430c88 --- /dev/null +++ b/YunusovComponentsLibrary/Form1/Program.cs @@ -0,0 +1,17 @@ +namespace Form1 +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new Form1()); + } + } +} \ No newline at end of file diff --git a/YunusovComponentsLibrary/Form1/TestPerson.cs b/YunusovComponentsLibrary/Form1/TestPerson.cs new file mode 100644 index 0000000..d5debf0 --- /dev/null +++ b/YunusovComponentsLibrary/Form1/TestPerson.cs @@ -0,0 +1,27 @@ +namespace YunusovComponentsLibrary +{ + public class TestPerson + { + public int Id { get; set; } + + public string Name { get; set; } = string.Empty; + + public string Yourname { get; set; } = string.Empty; + + public int Age { get; set; } + public TestPerson() + { } + + public TestPerson(int Id, string Name, string Yourname, int Age) + { + this.Id = Id; + this.Name = Name; + this.Yourname = Yourname; + this.Age = Age; + } + public override string ToString() + { + return $"[{Id}] {Name} {Yourname}. Возраст: {Age}"; + } + } +} diff --git a/YunusovComponentsLibrary/YunusovComponentsLibrary.sln b/YunusovComponentsLibrary/YunusovComponentsLibrary.sln new file mode 100644 index 0000000..b50446d --- /dev/null +++ b/YunusovComponentsLibrary/YunusovComponentsLibrary.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34221.43 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YunusovComponentsLibrary", "YunusovComponentsLibrary\YunusovComponentsLibrary.csproj", "{FADF2E43-1F76-4A8B-A586-4D59676F6335}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Form1", "Form1\Form1.csproj", "{9A55F075-005A-433D-B6CC-89E850999353}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FADF2E43-1F76-4A8B-A586-4D59676F6335}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FADF2E43-1F76-4A8B-A586-4D59676F6335}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FADF2E43-1F76-4A8B-A586-4D59676F6335}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FADF2E43-1F76-4A8B-A586-4D59676F6335}.Release|Any CPU.Build.0 = Release|Any CPU + {9A55F075-005A-433D-B6CC-89E850999353}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9A55F075-005A-433D-B6CC-89E850999353}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9A55F075-005A-433D-B6CC-89E850999353}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9A55F075-005A-433D-B6CC-89E850999353}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {5A6AC5CC-7959-44F7-8CAC-06D9B6C31516} + EndGlobalSection +EndGlobal diff --git a/YunusovComponentsLibrary/YunusovComponentsLibrary/Class1.cs b/YunusovComponentsLibrary/YunusovComponentsLibrary/Class1.cs new file mode 100644 index 0000000..d8d1f55 --- /dev/null +++ b/YunusovComponentsLibrary/YunusovComponentsLibrary/Class1.cs @@ -0,0 +1,6 @@ +namespace YunusovComponentsLibrary +{ + public class Class1 + { + } +} \ No newline at end of file diff --git a/YunusovComponentsLibrary/YunusovComponentsLibrary/ColumnInfo.cs b/YunusovComponentsLibrary/YunusovComponentsLibrary/ColumnInfo.cs new file mode 100644 index 0000000..32e7b38 --- /dev/null +++ b/YunusovComponentsLibrary/YunusovComponentsLibrary/ColumnInfo.cs @@ -0,0 +1,16 @@ +namespace YunusovComponentsLibrary +{ + public class ColumnInfo + { + public int ColumnsCount { get; set; } + + public string[] Header { get; set; } + + public int[] Width { get; set; } + + public bool[] IsVisible { get; set; } + + public string[] PropertiesName { get; set; } + + } +} diff --git a/YunusovComponentsLibrary/YunusovComponentsLibrary/Exceptions/EmptyValueException.cs b/YunusovComponentsLibrary/YunusovComponentsLibrary/Exceptions/EmptyValueException.cs new file mode 100644 index 0000000..169129c --- /dev/null +++ b/YunusovComponentsLibrary/YunusovComponentsLibrary/Exceptions/EmptyValueException.cs @@ -0,0 +1,9 @@ +namespace YunusovComponentsLibrary.Exceptions +{ + public class EmptyValueException : ApplicationException + { + public EmptyValueException() + : base("Значение не введено") + { } + } +} diff --git a/YunusovComponentsLibrary/YunusovComponentsLibrary/Exceptions/NotFloatException.cs b/YunusovComponentsLibrary/YunusovComponentsLibrary/Exceptions/NotFloatException.cs new file mode 100644 index 0000000..a0b18c5 --- /dev/null +++ b/YunusovComponentsLibrary/YunusovComponentsLibrary/Exceptions/NotFloatException.cs @@ -0,0 +1,9 @@ +namespace YunusovComponentsLibrary.Exceptions +{ + public class NotFloatException : ApplicationException + { + public NotFloatException() + : base("Введенное значение не является вещественным") + { } + } +} diff --git a/YunusovComponentsLibrary/YunusovComponentsLibrary/InputComponent.Designer.cs b/YunusovComponentsLibrary/YunusovComponentsLibrary/InputComponent.Designer.cs new file mode 100644 index 0000000..152e962 --- /dev/null +++ b/YunusovComponentsLibrary/YunusovComponentsLibrary/InputComponent.Designer.cs @@ -0,0 +1,68 @@ +namespace YunusovComponentsLibrary +{ + partial class InputComponent + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + IsNullCheckBox = new CheckBox(); + textBoxInput = new TextBox(); + SuspendLayout(); + // + // IsNullCheckBox + // + IsNullCheckBox.AutoSize = true; + IsNullCheckBox.Location = new Point(13, 20); + IsNullCheckBox.Name = "IsNullCheckBox"; + IsNullCheckBox.Size = new Size(18, 17); + IsNullCheckBox.TabIndex = 0; + IsNullCheckBox.UseVisualStyleBackColor = true; + // + // textBoxInput + // + textBoxInput.Location = new Point(37, 14); + textBoxInput.Name = "textBoxInput"; + textBoxInput.Size = new Size(125, 27); + textBoxInput.TabIndex = 1; + // + // InputComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(textBoxInput); + Controls.Add(IsNullCheckBox); + Name = "InputComponent"; + Size = new Size(170, 55); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private CheckBox IsNullCheckBox; + private TextBox textBoxInput; + } +} diff --git a/YunusovComponentsLibrary/YunusovComponentsLibrary/InputComponent.cs b/YunusovComponentsLibrary/YunusovComponentsLibrary/InputComponent.cs new file mode 100644 index 0000000..9a67450 --- /dev/null +++ b/YunusovComponentsLibrary/YunusovComponentsLibrary/InputComponent.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using YunusovComponentsLibrary.Exceptions; + +namespace YunusovComponentsLibrary +{ + public partial class InputComponent : UserControl + { + private event EventHandler? _valueChanged; + public InputComponent() + { + InitializeComponent(); + } + public float? FloatValue + { + get + { + if (IsNullCheckBox.Checked) + { + return null; + } + + if (string.IsNullOrEmpty(textBoxInput.Text)) + { + throw new EmptyValueException(); + } + + float ParsedFloat; + if (float.TryParse(textBoxInput.Text, out ParsedFloat)) + { + return ParsedFloat; + } + else + { + throw new NotFloatException(); + } + } + set + { + SetNullState(value is null, true); + if (value is not null) + { + textBoxInput.Text = value.ToString(); + } + } + } + public event EventHandler? ValueChanged + { + add { _valueChanged += value; } + remove { _valueChanged -= value; } + } + private void SetNullState(bool IsNull = false, bool ClearText = false) + { + IsNullCheckBox.Checked = IsNull; + textBoxInput.Enabled = !IsNull; + + if (ClearText) + { + textBoxInput.Text = string.Empty; + } + } + + private void textBox_TextChanged(object sender, EventArgs e) + { + _valueChanged?.Invoke(this, e); + } + } +} diff --git a/YunusovComponentsLibrary/YunusovComponentsLibrary/InputComponent.resx b/YunusovComponentsLibrary/YunusovComponentsLibrary/InputComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/YunusovComponentsLibrary/YunusovComponentsLibrary/InputComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/YunusovComponentsLibrary/YunusovComponentsLibrary/ListOutputComponent.Designer.cs b/YunusovComponentsLibrary/YunusovComponentsLibrary/ListOutputComponent.Designer.cs new file mode 100644 index 0000000..2b3b6ab --- /dev/null +++ b/YunusovComponentsLibrary/YunusovComponentsLibrary/ListOutputComponent.Designer.cs @@ -0,0 +1,60 @@ +namespace YunusovComponentsLibrary +{ + partial class ListOutputComponent + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(597, 335); + dataGridView.TabIndex = 0; + // + // ListOutputComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(dataGridView); + Name = "ListOutputComponent"; + Size = new Size(600, 338); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + } +} diff --git a/YunusovComponentsLibrary/YunusovComponentsLibrary/ListOutputComponent.cs b/YunusovComponentsLibrary/YunusovComponentsLibrary/ListOutputComponent.cs new file mode 100644 index 0000000..16a83d5 --- /dev/null +++ b/YunusovComponentsLibrary/YunusovComponentsLibrary/ListOutputComponent.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace YunusovComponentsLibrary +{ + public partial class ListOutputComponent : UserControl + { + public ListOutputComponent() + { + InitializeComponent(); + } + public DataGridViewRowCollection Rows + { + get { return dataGridView.Rows; } + } + public int SelectedRow + { + get + { + return dataGridView.SelectedRows.Count == 1 ? dataGridView.SelectedRows[0].Index : -1; + } + set + { + if (value >= 0 && value < dataGridView.Rows.Count) + { + dataGridView.Rows[value].Selected = true; + } + } + } + public void ConfigColumn(ColumnInfo columns) + { + if (columns.ColumnsCount != columns.Header.Length || + columns.ColumnsCount != columns.Width.Length || + columns.ColumnsCount != columns.IsVisible.Length || + columns.ColumnsCount != columns.PropertiesName.Length) + throw new ArgumentException("All arrays must have the same length."); + + dataGridView.Columns.Clear(); + + dataGridView.ColumnCount = columns.ColumnsCount; + + for (int i = 0; i < columns.ColumnsCount; ++i) + { + dataGridView.Columns[i].HeaderText = columns.Header[i]; + dataGridView.Columns[i].Width = columns.Width[i]; + dataGridView.Columns[i].Visible = columns.IsVisible[i]; + dataGridView.Columns[i].Name = columns.PropertiesName[i]; + } + } + public void ClearDataGridView() + { + dataGridView.Rows.Clear(); + } + public T GetSelectedObject() where T : class, new() + { + T obj = new (); + var properties = typeof(T).GetProperties(); + + foreach (var property in properties) + { + var cellValue = dataGridView.Rows[SelectedRow].Cells[property.Name].Value; + if (cellValue != null) + { + property.SetValue(obj, Convert.ChangeType(cellValue, property.PropertyType)); + } + } + + return obj; + } + public void AddItem(T item) + { + if (item == null) + return; + + int rowIndex = dataGridView.Rows.Add(); + + foreach (var property in typeof(T).GetProperties()) + { + var value = property.GetValue(item); + dataGridView.Rows[rowIndex].Cells[property.Name].Value = value; + } + } + } +} diff --git a/YunusovComponentsLibrary/YunusovComponentsLibrary/ListOutputComponent.resx b/YunusovComponentsLibrary/YunusovComponentsLibrary/ListOutputComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/YunusovComponentsLibrary/YunusovComponentsLibrary/ListOutputComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/YunusovComponentsLibrary/YunusovComponentsLibrary/SelectedComponent.Designer.cs b/YunusovComponentsLibrary/YunusovComponentsLibrary/SelectedComponent.Designer.cs new file mode 100644 index 0000000..c04914e --- /dev/null +++ b/YunusovComponentsLibrary/YunusovComponentsLibrary/SelectedComponent.Designer.cs @@ -0,0 +1,58 @@ +namespace YunusovComponentsLibrary +{ + partial class SelectedComponent + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + listBox = new ListBox(); + SuspendLayout(); + // + // listBox + // + listBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + listBox.FormattingEnabled = true; + listBox.ItemHeight = 20; + listBox.Location = new Point(3, 3); + listBox.Name = "listBox"; + listBox.Size = new Size(125, 164); + listBox.TabIndex = 0; + // + // SelectedComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(listBox); + Name = "SelectedComponent"; + Size = new Size(131, 181); + ResumeLayout(false); + } + + #endregion + + private ListBox listBox; + } +} diff --git a/YunusovComponentsLibrary/YunusovComponentsLibrary/SelectedComponent.cs b/YunusovComponentsLibrary/YunusovComponentsLibrary/SelectedComponent.cs new file mode 100644 index 0000000..7b24efe --- /dev/null +++ b/YunusovComponentsLibrary/YunusovComponentsLibrary/SelectedComponent.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace YunusovComponentsLibrary +{ + public partial class SelectedComponent : UserControl + { + private event EventHandler _itemSelected; + public SelectedComponent() + { + InitializeComponent(); + } + public void Input(string str) + { + if (string.IsNullOrEmpty(str)) + throw new ArgumentNullException("input"); + listBox.Items.Add(str); + } + public void ClearList() + { + listBox.Items.Clear(); + } + public string SelectedItem + { + get { return (string)listBox.SelectedItem ?? string.Empty; } + set { listBox.SelectedItem = value; } + } + public event EventHandler? ItemSelected + { + add { _itemSelected += value; } + remove { _itemSelected -= value; } + } + private void listBox_SelectedIndexChanged(object sender, EventArgs e) + { + _itemSelected?.Invoke(this, e); + } + } +} diff --git a/YunusovComponentsLibrary/YunusovComponentsLibrary/SelectedComponent.resx b/YunusovComponentsLibrary/YunusovComponentsLibrary/SelectedComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/YunusovComponentsLibrary/YunusovComponentsLibrary/SelectedComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/YunusovComponentsLibrary/YunusovComponentsLibrary/Testing.Designer.cs b/YunusovComponentsLibrary/YunusovComponentsLibrary/Testing.Designer.cs new file mode 100644 index 0000000..8e5879f --- /dev/null +++ b/YunusovComponentsLibrary/YunusovComponentsLibrary/Testing.Designer.cs @@ -0,0 +1,73 @@ +namespace YunusovComponentsLibrary +{ + partial class Testing + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + pictureBox = new PictureBox(); + button = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + SuspendLayout(); + // + // pictureBox + // + pictureBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + pictureBox.Location = new Point(3, 3); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(187, 150); + pictureBox.TabIndex = 0; + pictureBox.TabStop = false; + // + // button + // + button.Anchor = AnchorStyles.Bottom; + button.Location = new Point(49, 156); + button.Name = "button"; + button.Size = new Size(94, 29); + button.TabIndex = 1; + button.Text = "Загрузить"; + button.UseVisualStyleBackColor = true; + button.Click += button_Click; + // + // Testing + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(button); + Controls.Add(pictureBox); + Name = "Testing"; + Size = new Size(193, 188); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private PictureBox pictureBox; + private Button button; + } +} diff --git a/YunusovComponentsLibrary/YunusovComponentsLibrary/Testing.cs b/YunusovComponentsLibrary/YunusovComponentsLibrary/Testing.cs new file mode 100644 index 0000000..e335707 --- /dev/null +++ b/YunusovComponentsLibrary/YunusovComponentsLibrary/Testing.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace YunusovComponentsLibrary +{ + public partial class Testing : UserControl + { + private event EventHandler? _avatarChanged; + private event Action? _errorOccured; + public string Error { get; private set; } + public Image Avatar + { + get + { + return pictureBox.Image; + } + set + { + pictureBox.Image = value; + } + } + public event EventHandler AvatarChanged + { + add { _avatarChanged += value; } + remove { _avatarChanged -= value; } + } + public event Action AnErrorOccurred + { + add { _errorOccured += value; } + remove { _errorOccured -= value; } + } + public Testing() + { + InitializeComponent(); + Error = string.Empty; + } + private void ButtonLoad_Click(object sender, EventArgs e) + { + var ofd = new OpenFileDialog(); + if (ofd.ShowDialog() == DialogResult.OK) + { + try + { + pictureBox.Image = + Image.FromFile(ofd.FileName); + _avatarChanged?.Invoke(this, e); + } + catch (Exception ex) + { + Error = ex.Message; + _errorOccured?.Invoke(); + } + } + } + + private void button_Click(object sender, EventArgs e) + { + + } + } +} diff --git a/YunusovComponentsLibrary/YunusovComponentsLibrary/Testing.resx b/YunusovComponentsLibrary/YunusovComponentsLibrary/Testing.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/YunusovComponentsLibrary/YunusovComponentsLibrary/Testing.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/YunusovComponentsLibrary/YunusovComponentsLibrary/YunusovComponentsLibrary.csproj b/YunusovComponentsLibrary/YunusovComponentsLibrary/YunusovComponentsLibrary.csproj new file mode 100644 index 0000000..060aa1c --- /dev/null +++ b/YunusovComponentsLibrary/YunusovComponentsLibrary/YunusovComponentsLibrary.csproj @@ -0,0 +1,10 @@ + + + + net6.0-windows + enable + true + enable + + +