diff --git a/WinFormsLibrary1.sln b/WinFormsLibrary1.sln new file mode 100644 index 0000000..497a321 --- /dev/null +++ b/WinFormsLibrary1.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34728.123 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormsLibrary1", "WinFormsLibrary1\WinFormsLibrary1.csproj", "{260D3E8C-3599-49F1-BF42-64A92DD0FB62}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsMain", "WinFormsMain\WinFormsMain.csproj", "{D671A342-9B1B-4662-B7CB-9E7382CCFBC7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {260D3E8C-3599-49F1-BF42-64A92DD0FB62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {260D3E8C-3599-49F1-BF42-64A92DD0FB62}.Debug|Any CPU.Build.0 = Debug|Any CPU + {260D3E8C-3599-49F1-BF42-64A92DD0FB62}.Release|Any CPU.ActiveCfg = Release|Any CPU + {260D3E8C-3599-49F1-BF42-64A92DD0FB62}.Release|Any CPU.Build.0 = Release|Any CPU + {D671A342-9B1B-4662-B7CB-9E7382CCFBC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D671A342-9B1B-4662-B7CB-9E7382CCFBC7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D671A342-9B1B-4662-B7CB-9E7382CCFBC7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D671A342-9B1B-4662-B7CB-9E7382CCFBC7}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1208CC7E-AF27-4982-8E30-0DC89F09BBA6} + EndGlobalSection +EndGlobal diff --git a/WinFormsLibrary1/ColumnInfo.cs b/WinFormsLibrary1/ColumnInfo.cs new file mode 100644 index 0000000..f504008 --- /dev/null +++ b/WinFormsLibrary1/ColumnInfo.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinFormsLibrary1 +{ + public class ColumnInfo + { + public string HeaderText { get; set; } = string.Empty; + public int Width { get; set; } + public bool Visible { get; set; } + public string Name { get; set; } = string.Empty; + public ColumnInfo(string headerText, string name, int width, bool visible) + { + HeaderText = headerText; + Name = name; + Width = width; + Visible = visible; + } + } +} diff --git a/WinFormsLibrary1/UncheckedNullException.cs b/WinFormsLibrary1/UncheckedNullException.cs new file mode 100644 index 0000000..73b6e8c --- /dev/null +++ b/WinFormsLibrary1/UncheckedNullException.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinFormsLibrary1 +{ + public class UncheckedNullException : Exception + { + public UncheckedNullException() { } + public UncheckedNullException(string message) : base(message) { } + } +} diff --git a/WinFormsLibrary1/UnexpectedTypeException.cs b/WinFormsLibrary1/UnexpectedTypeException.cs new file mode 100644 index 0000000..19eace9 --- /dev/null +++ b/WinFormsLibrary1/UnexpectedTypeException.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinFormsLibrary1 +{ + public class UnexpectedTypeException : Exception + { + public UnexpectedTypeException() { } + public UnexpectedTypeException(string message) : base(message) { } + } +} diff --git a/WinFormsLibrary1/User.cs b/WinFormsLibrary1/User.cs new file mode 100644 index 0000000..8a521b8 --- /dev/null +++ b/WinFormsLibrary1/User.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinFormsLibrary1 +{ + public class User + { + public string username { get; private set; } + public string email { get; private set; } + public DateTime birthday { get; private set; } + + public User(string username, string email, DateTime birthday) + { + this.username = username; + this.email = email; + this.birthday = birthday; + } + + } +} diff --git a/WinFormsLibrary1/UserControlIntegerInput.Designer.cs b/WinFormsLibrary1/UserControlIntegerInput.Designer.cs new file mode 100644 index 0000000..e978ffc --- /dev/null +++ b/WinFormsLibrary1/UserControlIntegerInput.Designer.cs @@ -0,0 +1,71 @@ +namespace WinFormsLibrary1 +{ + partial class UserControlIntegerInput + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + textBoxInteger = new TextBox(); + checkBoxNullable = new CheckBox(); + SuspendLayout(); + // + // textBoxInteger + // + textBoxInteger.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + textBoxInteger.Location = new Point(24, 1); + textBoxInteger.Name = "textBoxInteger"; + textBoxInteger.Size = new Size(144, 23); + textBoxInteger.TabIndex = 0; + textBoxInteger.TextChanged += textBoxInteger_TextChanged; + // + // checkBoxNullable + // + checkBoxNullable.AutoSize = true; + checkBoxNullable.Location = new Point(3, 5); + checkBoxNullable.Name = "checkBoxNullable"; + checkBoxNullable.Size = new Size(15, 14); + checkBoxNullable.TabIndex = 1; + checkBoxNullable.UseVisualStyleBackColor = true; + checkBoxNullable.CheckedChanged += checkBoxNullable_CheckedChanged; + // + // UserControlIntegerInput + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(checkBoxNullable); + Controls.Add(textBoxInteger); + Name = "UserControlIntegerInput"; + Size = new Size(171, 30); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxInteger; + private CheckBox checkBoxNullable; + } +} diff --git a/WinFormsLibrary1/UserControlIntegerInput.cs b/WinFormsLibrary1/UserControlIntegerInput.cs new file mode 100644 index 0000000..3413573 --- /dev/null +++ b/WinFormsLibrary1/UserControlIntegerInput.cs @@ -0,0 +1,70 @@ +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 WinFormsLibrary1 +{ + public partial class UserControlIntegerInput : UserControl + { + private event EventHandler? _elementChanged; + private event Action? _errorOccured; + public string Error { get; private set; } + public int? InputtedInteger + { + get + { + if (checkBoxNullable.Checked) + { + return null; + } + if (textBoxInteger.Text.Equals(string.Empty) || textBoxInteger.Text == null) + { + throw new UncheckedNullException("Input was null, but checkbox wasnt checked"); + } + if (Int32.TryParse(textBoxInteger.Text, out var number)) + { + return number; + } + throw new UnexpectedTypeException("Input was non integer"); + } + set + { + textBoxInteger.Text = value.ToString(); + checkBoxNullable.Checked = value == null; + } + } + public event EventHandler ElementChanged + { + add { _elementChanged += value; } + remove { _elementChanged -= value; } + } + public event Action AnErrorOccurred + { + add { _errorOccured += value; } + remove { _errorOccured -= value; } + } + public UserControlIntegerInput() + { + InitializeComponent(); + Error = string.Empty; + } + + private void textBoxInteger_TextChanged(object sender, EventArgs e) + { + _elementChanged?.Invoke(this, e); + } + + private void checkBoxNullable_CheckedChanged(object sender, EventArgs e) + { + textBoxInteger.Enabled = !checkBoxNullable.Checked; + textBoxInteger.Text = null; + _elementChanged?.Invoke(this, e); + } + } +} diff --git a/WinFormsLibrary1/UserControlIntegerInput.resx b/WinFormsLibrary1/UserControlIntegerInput.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/WinFormsLibrary1/UserControlIntegerInput.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/WinFormsLibrary1/UserControlStringsListBox.Designer.cs b/WinFormsLibrary1/UserControlStringsListBox.Designer.cs new file mode 100644 index 0000000..6b42aee --- /dev/null +++ b/WinFormsLibrary1/UserControlStringsListBox.Designer.cs @@ -0,0 +1,58 @@ +namespace WinFormsLibrary1 +{ + partial class UserControlStringsListBox + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + listBoxStrings = new ListBox(); + SuspendLayout(); + // + // listBoxStrings + // + listBoxStrings.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + listBoxStrings.FormattingEnabled = true; + listBoxStrings.ItemHeight = 15; + listBoxStrings.Location = new Point(3, 3); + listBoxStrings.Name = "listBoxStrings"; + listBoxStrings.Size = new Size(144, 139); + listBoxStrings.TabIndex = 0; + listBoxStrings.SelectedValueChanged += listBoxStrings_SelectedValueChanged; + // + // UserControlStringsListBox + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(listBoxStrings); + Name = "UserControlStringsListBox"; + ResumeLayout(false); + } + + #endregion + + private ListBox listBoxStrings; + } +} diff --git a/WinFormsLibrary1/UserControlStringsListBox.cs b/WinFormsLibrary1/UserControlStringsListBox.cs new file mode 100644 index 0000000..0cf9580 --- /dev/null +++ b/WinFormsLibrary1/UserControlStringsListBox.cs @@ -0,0 +1,70 @@ +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 WinFormsLibrary1 +{ + public partial class UserControlStringsListBox : UserControl + { + private event EventHandler? _listChanged; + private event Action? _errorOccured; + public string Error { get; private set; } + public string ListElement + { + get + { + return listBoxStrings.SelectedItem?.ToString(); + } + set + { + if (listBoxStrings.Items.Contains(value)) + { + listBoxStrings.SelectedItem = value; + } + } + } + public event EventHandler ListChanged + { + add { _listChanged += value; } + remove { _listChanged -= value; } + } + public event Action AnErrorOccurred + { + add { _errorOccured += value; } + remove { _errorOccured -= value; } + } + public UserControlStringsListBox() + { + InitializeComponent(); + Error = string.Empty; + } + + public void AddList(List l) + { + try + { + listBoxStrings.Items.AddRange(l.ToArray()); + } + catch (Exception ex) + { + Error = ex.Message; + _errorOccured?.Invoke(); + } + } + public void ClearList() + { + listBoxStrings.Items.Clear(); + } + + private void listBoxStrings_SelectedValueChanged(object sender, EventArgs e) + { + _listChanged?.Invoke(sender, e); + } + } +} diff --git a/WinFormsLibrary1/UserControlStringsListBox.resx b/WinFormsLibrary1/UserControlStringsListBox.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/WinFormsLibrary1/UserControlStringsListBox.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/WinFormsLibrary1/UserControlTable.Designer.cs b/WinFormsLibrary1/UserControlTable.Designer.cs new file mode 100644 index 0000000..9db1b39 --- /dev/null +++ b/WinFormsLibrary1/UserControlTable.Designer.cs @@ -0,0 +1,62 @@ +namespace WinFormsLibrary1 +{ + partial class UserControlTable + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + dataGridViewTable = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridViewTable).BeginInit(); + SuspendLayout(); + // + // dataGridViewTable + // + dataGridViewTable.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridViewTable.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewTable.Location = new Point(3, 3); + dataGridViewTable.Name = "dataGridViewTable"; + dataGridViewTable.RowHeadersVisible = false; + dataGridViewTable.RowTemplate.Height = 25; + dataGridViewTable.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewTable.Size = new Size(325, 150); + dataGridViewTable.TabIndex = 0; + // + // UserControlTable + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(dataGridViewTable); + Name = "UserControlTable"; + Size = new Size(331, 157); + ((System.ComponentModel.ISupportInitialize)dataGridViewTable).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridViewTable; + } +} diff --git a/WinFormsLibrary1/UserControlTable.cs b/WinFormsLibrary1/UserControlTable.cs new file mode 100644 index 0000000..f341e31 --- /dev/null +++ b/WinFormsLibrary1/UserControlTable.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WinFormsLibrary1 +{ + public partial class UserControlTable : UserControl + { + public int index + { + get => dataGridViewTable.SelectedRows.Count > 0 ? dataGridViewTable.SelectedRows[0].Index : -1; + set + { + if (value >= 0 && value < dataGridViewTable.Rows.Count) + { + dataGridViewTable.ClearSelection(); + dataGridViewTable.Rows[value].Selected = true; + } + } + } + public UserControlTable() + { + InitializeComponent(); + } + + public void ConfigureColumns(List columnInfo) + { + dataGridViewTable.Columns.Clear(); + for (int i = 0; i < columnInfo.Count; i++) + { + DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn + { + Name = columnInfo[i].Name, + HeaderText = columnInfo[i].HeaderText, + Width = columnInfo[i].Width, + Visible = columnInfo[i].Visible, + }; + dataGridViewTable.Columns.Add(column); + } + } + + public void ClearRows() + { + dataGridViewTable.Rows.Clear(); + } + + public void AddObjectList(List os) + { + dataGridViewTable.DataSource = os ?? throw new ArgumentNullException(); + } + + public T GetObjectFromRow() + where T : new() + { + if (dataGridViewTable.SelectedRows.Count == 0) + { + throw new InvalidOperationException("At least one row must be selected"); + } + + T returnObject = new(); + + var selectedRow = dataGridViewTable.SelectedRows[0]; + var props = typeof(T).GetProperties(); + var cells = dataGridViewTable.Rows[selectedRow.Index].Cells; + + for (int i = 0; i < dataGridViewTable.ColumnCount; i++) + { + var curCell = cells[i]; + var prop = props.FirstOrDefault(x => x.Name == dataGridViewTable.Columns[i].Name); + prop?.SetValue(returnObject, curCell.Value); + } + return returnObject; + } + + public void AddList (List values) + { + ClearRows(); + var props = typeof(T).GetProperties(); + + foreach (T value in values) + { + int newRowInd = dataGridViewTable.Rows.Add(value); + foreach (DataGridViewColumn col in dataGridViewTable.Columns) + { + var prop = props.FirstOrDefault(x => x.Name == col.Name) + ?? throw new InvalidOperationException($"No property {col.Name} found in type {typeof(T).Name}"); + var val = prop.GetValue(value); + dataGridViewTable.Rows[newRowInd].Cells[col.Index].Value = val; + } + } + } + } +} diff --git a/WinFormsLibrary1/UserControlTable.resx b/WinFormsLibrary1/UserControlTable.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/WinFormsLibrary1/UserControlTable.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/WinFormsLibrary1/WinFormsLibrary1.csproj b/WinFormsLibrary1/WinFormsLibrary1.csproj new file mode 100644 index 0000000..3d78086 --- /dev/null +++ b/WinFormsLibrary1/WinFormsLibrary1.csproj @@ -0,0 +1,10 @@ + + + + net7.0-windows + enable + true + enable + + + diff --git a/WinFormsMain/Form1.Designer.cs b/WinFormsMain/Form1.Designer.cs new file mode 100644 index 0000000..6712231 --- /dev/null +++ b/WinFormsMain/Form1.Designer.cs @@ -0,0 +1,244 @@ +namespace WinFormsMain +{ + 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() + { + groupBox1 = new GroupBox(); + buttonSetList = new Button(); + textBoxList = new TextBox(); + buttonCheckSelected = new Button(); + labelListStatus = new Label(); + label1 = new Label(); + buttonAddTestList = new Button(); + buttonClearList = new Button(); + userControlStringsListBox = new WinFormsLibrary1.UserControlStringsListBox(); + groupBox2 = new GroupBox(); + userControlTable = new WinFormsLibrary1.UserControlTable(); + groupBox3 = new GroupBox(); + buttonSetInputtedInteger = new Button(); + textBoxInputtedInteger = new TextBox(); + buttonGetInputtedValue = new Button(); + userControlIntegerInput = new WinFormsLibrary1.UserControlIntegerInput(); + groupBox1.SuspendLayout(); + groupBox2.SuspendLayout(); + groupBox3.SuspendLayout(); + SuspendLayout(); + // + // groupBox1 + // + groupBox1.Controls.Add(buttonSetList); + groupBox1.Controls.Add(textBoxList); + groupBox1.Controls.Add(buttonCheckSelected); + groupBox1.Controls.Add(labelListStatus); + groupBox1.Controls.Add(label1); + groupBox1.Controls.Add(buttonAddTestList); + groupBox1.Controls.Add(buttonClearList); + groupBox1.Controls.Add(userControlStringsListBox); + groupBox1.Location = new Point(12, 12); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(225, 413); + groupBox1.TabIndex = 0; + groupBox1.TabStop = false; + groupBox1.Text = "Визуальный компонент выбора"; + // + // buttonSetList + // + buttonSetList.Location = new Point(144, 300); + buttonSetList.Name = "buttonSetList"; + buttonSetList.Size = new Size(75, 23); + buttonSetList.TabIndex = 7; + buttonSetList.Text = "Выбрать"; + buttonSetList.UseVisualStyleBackColor = true; + buttonSetList.Click += buttonSetList_Click; + // + // textBoxList + // + textBoxList.Location = new Point(6, 300); + textBoxList.Name = "textBoxList"; + textBoxList.Size = new Size(132, 23); + textBoxList.TabIndex = 6; + // + // buttonCheckSelected + // + buttonCheckSelected.Location = new Point(6, 256); + buttonCheckSelected.Name = "buttonCheckSelected"; + buttonCheckSelected.Size = new Size(213, 33); + buttonCheckSelected.TabIndex = 5; + buttonCheckSelected.Text = "Выбранный элемент"; + buttonCheckSelected.UseVisualStyleBackColor = true; + buttonCheckSelected.Click += buttonCheckSelected_Click; + // + // labelListStatus + // + labelListStatus.AutoSize = true; + labelListStatus.Location = new Point(22, 387); + labelListStatus.Name = "labelListStatus"; + labelListStatus.Size = new Size(0, 15); + labelListStatus.TabIndex = 4; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(6, 360); + label1.Name = "label1"; + label1.Size = new Size(87, 15); + label1.TabIndex = 3; + label1.Text = "Статус списка:"; + // + // buttonAddTestList + // + buttonAddTestList.Location = new Point(6, 178); + buttonAddTestList.Name = "buttonAddTestList"; + buttonAddTestList.Size = new Size(213, 33); + buttonAddTestList.TabIndex = 2; + buttonAddTestList.Text = "Добавить список из 5 элементов"; + buttonAddTestList.UseVisualStyleBackColor = true; + buttonAddTestList.Click += buttonAddTestList_Click; + // + // buttonClearList + // + buttonClearList.Location = new Point(6, 217); + buttonClearList.Name = "buttonClearList"; + buttonClearList.Size = new Size(213, 33); + buttonClearList.TabIndex = 1; + buttonClearList.Text = "Очистить"; + buttonClearList.UseVisualStyleBackColor = true; + buttonClearList.Click += buttonClearList_Click; + // + // userControlStringsListBox + // + userControlStringsListBox.ListElement = ""; + userControlStringsListBox.Location = new Point(6, 22); + userControlStringsListBox.Name = "userControlStringsListBox"; + userControlStringsListBox.Size = new Size(213, 150); + userControlStringsListBox.TabIndex = 0; + userControlStringsListBox.ListChanged += userControlStringsListBox_ListChanged; + // + // groupBox2 + // + groupBox2.Controls.Add(userControlTable); + groupBox2.Location = new Point(496, 12); + groupBox2.Name = "groupBox2"; + groupBox2.Size = new Size(344, 323); + groupBox2.TabIndex = 1; + groupBox2.TabStop = false; + groupBox2.Text = "Визуальный компонент вывода списков"; + // + // userControlTable + // + userControlTable.index = -1; + userControlTable.Location = new Point(7, 22); + userControlTable.Name = "userControlTable"; + userControlTable.Size = new Size(331, 157); + userControlTable.TabIndex = 0; + // + // groupBox3 + // + groupBox3.Controls.Add(buttonSetInputtedInteger); + groupBox3.Controls.Add(textBoxInputtedInteger); + groupBox3.Controls.Add(buttonGetInputtedValue); + groupBox3.Controls.Add(userControlIntegerInput); + groupBox3.Location = new Point(243, 12); + groupBox3.Name = "groupBox3"; + groupBox3.Size = new Size(247, 384); + groupBox3.TabIndex = 2; + groupBox3.TabStop = false; + groupBox3.Text = "Визуальный компонент ввода"; + // + // buttonSetInputtedInteger + // + buttonSetInputtedInteger.Location = new Point(166, 115); + buttonSetInputtedInteger.Name = "buttonSetInputtedInteger"; + buttonSetInputtedInteger.Size = new Size(75, 23); + buttonSetInputtedInteger.TabIndex = 8; + buttonSetInputtedInteger.Text = "Заменить"; + buttonSetInputtedInteger.UseVisualStyleBackColor = true; + buttonSetInputtedInteger.Click += buttonSetInputtedInteger_Click; + // + // textBoxInputtedInteger + // + textBoxInputtedInteger.Location = new Point(6, 115); + textBoxInputtedInteger.Name = "textBoxInputtedInteger"; + textBoxInputtedInteger.Size = new Size(154, 23); + textBoxInputtedInteger.TabIndex = 2; + // + // buttonGetInputtedValue + // + buttonGetInputtedValue.Location = new Point(6, 58); + buttonGetInputtedValue.Name = "buttonGetInputtedValue"; + buttonGetInputtedValue.Size = new Size(235, 42); + buttonGetInputtedValue.TabIndex = 1; + buttonGetInputtedValue.Text = "Получить значение"; + buttonGetInputtedValue.UseVisualStyleBackColor = true; + buttonGetInputtedValue.Click += buttonGetInputtedValue_Click; + // + // userControlIntegerInput + // + userControlIntegerInput.Location = new Point(6, 22); + userControlIntegerInput.Name = "userControlIntegerInput"; + userControlIntegerInput.Size = new Size(235, 30); + userControlIntegerInput.TabIndex = 0; + // + // Form1 + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(849, 437); + Controls.Add(groupBox3); + Controls.Add(groupBox2); + Controls.Add(groupBox1); + Name = "Form1"; + Text = "Основная форма"; + groupBox1.ResumeLayout(false); + groupBox1.PerformLayout(); + groupBox2.ResumeLayout(false); + groupBox3.ResumeLayout(false); + groupBox3.PerformLayout(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBox1; + private WinFormsLibrary1.UserControlStringsListBox userControlStringsListBox; + private GroupBox groupBox2; + private WinFormsLibrary1.UserControlTable userControlTable; + private GroupBox groupBox3; + private WinFormsLibrary1.UserControlIntegerInput userControlIntegerInput; + private Button buttonAddTestList; + private Button buttonClearList; + private Label labelListStatus; + private Label label1; + private Button buttonCheckSelected; + private Button buttonGetInputtedValue; + private Button buttonSetList; + private TextBox textBoxList; + private Button buttonSetInputtedInteger; + private TextBox textBoxInputtedInteger; + } +} diff --git a/WinFormsMain/Form1.cs b/WinFormsMain/Form1.cs new file mode 100644 index 0000000..75abb3f --- /dev/null +++ b/WinFormsMain/Form1.cs @@ -0,0 +1,67 @@ +namespace WinFormsMain +{ + public partial class Form1 : Form + { + private Random rnd = new Random(); + public Form1() + { + InitializeComponent(); + } + + private void buttonAddTestList_Click(object sender, EventArgs e) + { + List testList = new List(); + for (int i = 0; i < 5; i++) + { + testList.Add("test " + i); + } + userControlStringsListBox.AddList(testList); + } + + private void buttonClearList_Click(object sender, EventArgs e) + { + userControlStringsListBox.ClearList(); + } + + private void userControlStringsListBox_ListChanged(object sender, EventArgs e) + { + labelListStatus.Text = userControlStringsListBox.ListElement; + } + + private void buttonCheckSelected_Click(object sender, EventArgs e) + { + MessageBox.Show(" \"" + userControlStringsListBox.ListElement + "\""); + } + + private void buttonSetList_Click(object sender, EventArgs e) + { + userControlStringsListBox.ListElement = textBoxList.Text; + } + + private void buttonSetInputtedInteger_Click(object sender, EventArgs e) + { + try + { + userControlIntegerInput.InputtedInteger = Convert.ToInt32(textBoxInputtedInteger.Text); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + + private void buttonGetInputtedValue_Click(object sender, EventArgs e) + { + int? i; + try + { + i = userControlIntegerInput.InputtedInteger; + MessageBox.Show(": \"" + i + "\""); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + } +} diff --git a/WinFormsMain/Form1.resx b/WinFormsMain/Form1.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/WinFormsMain/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/WinFormsMain/Program.cs b/WinFormsMain/Program.cs new file mode 100644 index 0000000..d7087fc --- /dev/null +++ b/WinFormsMain/Program.cs @@ -0,0 +1,17 @@ +namespace WinFormsMain +{ + 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/WinFormsMain/WinFormsMain.csproj b/WinFormsMain/WinFormsMain.csproj new file mode 100644 index 0000000..be88b1e --- /dev/null +++ b/WinFormsMain/WinFormsMain.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net7.0-windows + enable + true + enable + + + + + + + \ No newline at end of file