From f39c73dca302e71673d2de73a343f04e038caca2 Mon Sep 17 00:00:00 2001 From: Arkadiy Radaev Date: Thu, 3 Oct 2024 21:53:25 +0400 Subject: [PATCH] Lab1 done --- Library15/Class1.cs | 6 + Library15/ColumnInfo.cs | 23 ++++ Library15/DefaultList.Designer.cs | 61 +++++++++ Library15/DefaultList.cs | 48 +++++++ Library15/DefaultList.resx | 120 +++++++++++++++++ Library15/Exceptions/EmptyValueException.cs | 15 +++ .../Exceptions/MalformedRealException.cs | 15 +++ Library15/InputRealNumber.Designer.cs | 72 ++++++++++ Library15/InputRealNumber.cs | 86 ++++++++++++ Library15/InputRealNumber.resx | 60 +++++++++ Library15/Library15.csproj | 10 ++ Library15/Library15.sln | 31 +++++ .../Models/CustomDataTableColumnParameter.cs | 13 ++ Library15/OutputTableResults.Designer.cs | 63 +++++++++ Library15/OutputTableResults.cs | 88 +++++++++++++ Library15/OutputTableResults.resx | 120 +++++++++++++++++ Library15/UserControl1.Designer.cs | 73 +++++++++++ Library15/UserControl1.cs | 63 +++++++++ Library15/UserControl1.resx | 120 +++++++++++++++++ WinFormsAppTest/Form1.Designer.cs | 124 ++++++++++++++++++ WinFormsAppTest/Form1.cs | 92 +++++++++++++ WinFormsAppTest/Form1.resx | 120 +++++++++++++++++ WinFormsAppTest/Program.cs | 17 +++ WinFormsAppTest/TestObject.cs | 30 +++++ WinFormsAppTest/WinFormsAppDone.csproj | 15 +++ WindowsFormsTest/App.config | 6 + WindowsFormsTest/Form1.Designer.cs | 40 ++++++ WindowsFormsTest/Form1.cs | 20 +++ WindowsFormsTest/Program.cs | 22 ++++ WindowsFormsTest/Properties/AssemblyInfo.cs | 36 +++++ .../Properties/Resources.Designer.cs | 71 ++++++++++ WindowsFormsTest/Properties/Resources.resx | 117 +++++++++++++++++ .../Properties/Settings.Designer.cs | 30 +++++ WindowsFormsTest/Properties/Settings.settings | 7 + WindowsFormsTest/WindowsFormsTest.csproj | 80 +++++++++++ 35 files changed, 1914 insertions(+) create mode 100644 Library15/Class1.cs create mode 100644 Library15/ColumnInfo.cs create mode 100644 Library15/DefaultList.Designer.cs create mode 100644 Library15/DefaultList.cs create mode 100644 Library15/DefaultList.resx create mode 100644 Library15/Exceptions/EmptyValueException.cs create mode 100644 Library15/Exceptions/MalformedRealException.cs create mode 100644 Library15/InputRealNumber.Designer.cs create mode 100644 Library15/InputRealNumber.cs create mode 100644 Library15/InputRealNumber.resx create mode 100644 Library15/Library15.csproj create mode 100644 Library15/Library15.sln create mode 100644 Library15/Models/CustomDataTableColumnParameter.cs create mode 100644 Library15/OutputTableResults.Designer.cs create mode 100644 Library15/OutputTableResults.cs create mode 100644 Library15/OutputTableResults.resx create mode 100644 Library15/UserControl1.Designer.cs create mode 100644 Library15/UserControl1.cs create mode 100644 Library15/UserControl1.resx create mode 100644 WinFormsAppTest/Form1.Designer.cs create mode 100644 WinFormsAppTest/Form1.cs create mode 100644 WinFormsAppTest/Form1.resx create mode 100644 WinFormsAppTest/Program.cs create mode 100644 WinFormsAppTest/TestObject.cs create mode 100644 WinFormsAppTest/WinFormsAppDone.csproj create mode 100644 WindowsFormsTest/App.config create mode 100644 WindowsFormsTest/Form1.Designer.cs create mode 100644 WindowsFormsTest/Form1.cs create mode 100644 WindowsFormsTest/Program.cs create mode 100644 WindowsFormsTest/Properties/AssemblyInfo.cs create mode 100644 WindowsFormsTest/Properties/Resources.Designer.cs create mode 100644 WindowsFormsTest/Properties/Resources.resx create mode 100644 WindowsFormsTest/Properties/Settings.Designer.cs create mode 100644 WindowsFormsTest/Properties/Settings.settings create mode 100644 WindowsFormsTest/WindowsFormsTest.csproj diff --git a/Library15/Class1.cs b/Library15/Class1.cs new file mode 100644 index 0000000..ef4dd08 --- /dev/null +++ b/Library15/Class1.cs @@ -0,0 +1,6 @@ +namespace Library15 +{ + public class Class1 + { + } +} \ No newline at end of file diff --git a/Library15/ColumnInfo.cs b/Library15/ColumnInfo.cs new file mode 100644 index 0000000..df4e3be --- /dev/null +++ b/Library15/ColumnInfo.cs @@ -0,0 +1,23 @@ +using Library15; + +namespace Library15 +{ + public class ColumnInfo + { + public string Header = string.Empty; + + public int Width; + + public bool IsVisible; + + public string Name = string.Empty; + + public ColumnInfo(string Header, int Width, bool IsVisible, string Name) + { + this.Header = Header; + this.Width = Width; + this.IsVisible = IsVisible; + this.Name = Name; + } + } +} diff --git a/Library15/DefaultList.Designer.cs b/Library15/DefaultList.Designer.cs new file mode 100644 index 0000000..970cfab --- /dev/null +++ b/Library15/DefaultList.Designer.cs @@ -0,0 +1,61 @@ +namespace Library15 +{ + partial class DefaultList + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + MainListBox = new ListBox(); + SuspendLayout(); + // + // MainListBox + // + MainListBox.FormattingEnabled = true; + MainListBox.ItemHeight = 25; + MainListBox.Items.AddRange(new object[] { "Sambuka", "Sanrase", "Gospacho", "Shamshev" }); + MainListBox.Location = new Point(4, 5); + MainListBox.Margin = new Padding(4, 5, 4, 5); + MainListBox.Name = "MainListBox"; + MainListBox.Size = new Size(138, 229); + MainListBox.TabIndex = 0; + MainListBox.TextChanged += new System.EventHandler(this.MainListBox_SelectedIndexChanged); + // + // DefaultList + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(MainListBox); + Margin = new Padding(4, 5, 4, 5); + Name = "DefaultList"; + Size = new Size(153, 250); + ResumeLayout(false); + } + + #endregion + + private ListBox MainListBox; + } +} diff --git a/Library15/DefaultList.cs b/Library15/DefaultList.cs new file mode 100644 index 0000000..3bf3d99 --- /dev/null +++ b/Library15/DefaultList.cs @@ -0,0 +1,48 @@ +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 Library15 +{ + public partial class DefaultList : UserControl + { + private event EventHandler? _itemSelected; + + public DefaultList() + { + InitializeComponent(); + } + + public void SetItems(string Items) + { + MainListBox.Items.Add(Items); + } + public void ClearList() + { + MainListBox.Items.Clear(); + } + + public string SelectedItem + { + get { return (string?)MainListBox.SelectedItem ?? string.Empty; } + set { MainListBox.SelectedItem = value; } + } + + public event EventHandler? ItemSelected + { + add { _itemSelected += value; } + remove { _itemSelected -= value; } + } + + private void MainListBox_SelectedIndexChanged(object sender, EventArgs e) + { + _itemSelected?.Invoke(this, e); + } + } +} diff --git a/Library15/DefaultList.resx b/Library15/DefaultList.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Library15/DefaultList.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/Library15/Exceptions/EmptyValueException.cs b/Library15/Exceptions/EmptyValueException.cs new file mode 100644 index 0000000..507786a --- /dev/null +++ b/Library15/Exceptions/EmptyValueException.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Library15.Exceptions +{ + public class EmptyValueException : ApplicationException + { + public EmptyValueException() + : base("Значение не введено") + { } + } +} diff --git a/Library15/Exceptions/MalformedRealException.cs b/Library15/Exceptions/MalformedRealException.cs new file mode 100644 index 0000000..b386191 --- /dev/null +++ b/Library15/Exceptions/MalformedRealException.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Library15.Exceptions +{ + public class MalformedRealException : ApplicationException + { + public MalformedRealException() + : base("Введенное значение не является вещественным") + { } + } +} diff --git a/Library15/InputRealNumber.Designer.cs b/Library15/InputRealNumber.Designer.cs new file mode 100644 index 0000000..7a3e7a4 --- /dev/null +++ b/Library15/InputRealNumber.Designer.cs @@ -0,0 +1,72 @@ +namespace Library15 +{ + partial class InputRealNumber + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + this.IsNullCheckBox = new System.Windows.Forms.CheckBox(); + this.MainTextBox = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // IsNullCheckBox + // + this.IsNullCheckBox.AutoSize = true; + this.IsNullCheckBox.Location = new System.Drawing.Point(3, 62); + this.IsNullCheckBox.Name = "IsNullCheckBox"; + this.IsNullCheckBox.Size = new System.Drawing.Size(127, 19); + this.IsNullCheckBox.TabIndex = 0; + this.IsNullCheckBox.Text = "Нулевое значение"; + this.IsNullCheckBox.UseVisualStyleBackColor = true; + this.IsNullCheckBox.CheckedChanged += new System.EventHandler(this.IsNullCheckBox_CheckedChanged); + // + // MainTextBox + // + this.MainTextBox.Location = new System.Drawing.Point(3, 20); + this.MainTextBox.Name = "MainTextBox"; + this.MainTextBox.Size = new System.Drawing.Size(127, 23); + this.MainTextBox.TabIndex = 1; + this.MainTextBox.TextChanged += new System.EventHandler(this.MainTextBox_TextChanged); + // + // InputRealNumber + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.MainTextBox); + this.Controls.Add(this.IsNullCheckBox); + this.Name = "InputRealNumber"; + this.Size = new System.Drawing.Size(135, 101); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private CheckBox IsNullCheckBox; + private TextBox MainTextBox; + } +} diff --git a/Library15/InputRealNumber.cs b/Library15/InputRealNumber.cs new file mode 100644 index 0000000..375a2f2 --- /dev/null +++ b/Library15/InputRealNumber.cs @@ -0,0 +1,86 @@ +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 Library15.Exceptions; + +namespace Library15 +{ + public partial class InputRealNumber : UserControl + { + private event EventHandler? _valueChanged; + + public InputRealNumber() + { + InitializeComponent(); + } + + public double? DoubleValue + { + get + { + if (IsNullCheckBox.Checked) + { + return null; + } + + if (string.IsNullOrEmpty(MainTextBox.Text)) + { + throw new EmptyValueException(); + } + + double ParsedDouble; + if (double.TryParse(MainTextBox.Text, out ParsedDouble)) + { + return ParsedDouble; + } + else + { + throw new MalformedRealException(); + } + } + set + { + SetNullState(value is null, true); + if (value is not null) + { + MainTextBox.Text = value.ToString(); + } + } + } + + public event EventHandler? ValueChanged + { + add { _valueChanged += value; } + remove { _valueChanged -= value; } + } + + + private void SetNullState(bool IsNull, bool ClearText = false) + { + IsNullCheckBox.Checked = IsNull; + MainTextBox.Enabled = !IsNull; + + if (ClearText) + { + MainTextBox.Text = string.Empty; + } + } + + private void IsNullCheckBox_CheckedChanged(object sender, EventArgs e) + { + SetNullState(IsNullCheckBox.Checked); + _valueChanged?.Invoke(this, e); + } + + private void MainTextBox_TextChanged(object sender, EventArgs e) + { + _valueChanged?.Invoke(this, e); + } + } +} diff --git a/Library15/InputRealNumber.resx b/Library15/InputRealNumber.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Library15/InputRealNumber.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Library15/Library15.csproj b/Library15/Library15.csproj new file mode 100644 index 0000000..060aa1c --- /dev/null +++ b/Library15/Library15.csproj @@ -0,0 +1,10 @@ + + + + net6.0-windows + enable + true + enable + + + diff --git a/Library15/Library15.sln b/Library15/Library15.sln new file mode 100644 index 0000000..9d62944 --- /dev/null +++ b/Library15/Library15.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32825.248 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library15", "Library15.csproj", "{460F98AD-977C-4ABE-B00B-1AA13D0D25C3}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormsAppDone", "..\WinFormsAppTest\WinFormsAppDone.csproj", "{00449FA8-BD19-4F9D-BE64-4B7AB52947A4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {460F98AD-977C-4ABE-B00B-1AA13D0D25C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {460F98AD-977C-4ABE-B00B-1AA13D0D25C3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {460F98AD-977C-4ABE-B00B-1AA13D0D25C3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {460F98AD-977C-4ABE-B00B-1AA13D0D25C3}.Release|Any CPU.Build.0 = Release|Any CPU + {00449FA8-BD19-4F9D-BE64-4B7AB52947A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {00449FA8-BD19-4F9D-BE64-4B7AB52947A4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {00449FA8-BD19-4F9D-BE64-4B7AB52947A4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {00449FA8-BD19-4F9D-BE64-4B7AB52947A4}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0F19F086-A3D3-46FF-955B-6834FFCCAEBB} + EndGlobalSection +EndGlobal diff --git a/Library15/Models/CustomDataTableColumnParameter.cs b/Library15/Models/CustomDataTableColumnParameter.cs new file mode 100644 index 0000000..3b88141 --- /dev/null +++ b/Library15/Models/CustomDataTableColumnParameter.cs @@ -0,0 +1,13 @@ +namespace Library15.Models +{ + public record CustomDataTableColumnParameter + { + public string HeaderName { get; init; } = string.Empty; + + public int Width { get; init; } = 0; + + public bool Visible { get; init; } = true; + + public string PropertyName { get; init; } = string.Empty; + } +} diff --git a/Library15/OutputTableResults.Designer.cs b/Library15/OutputTableResults.Designer.cs new file mode 100644 index 0000000..71ea687 --- /dev/null +++ b/Library15/OutputTableResults.Designer.cs @@ -0,0 +1,63 @@ +namespace Library15 +{ + partial class OutputTableResults + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + dataGridViewOut = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridViewOut).BeginInit(); + SuspendLayout(); + // + // dataGridViewOut + // + dataGridViewOut.BackgroundColor = SystemColors.ActiveCaption; + dataGridViewOut.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewOut.Location = new Point(4, 5); + dataGridViewOut.Margin = new Padding(4, 5, 4, 5); + dataGridViewOut.Name = "dataGridViewOut"; + dataGridViewOut.RowHeadersWidth = 62; + dataGridViewOut.RowTemplate.Height = 25; + dataGridViewOut.Size = new Size(567, 370); + dataGridViewOut.TabIndex = 0; + // + // OutputTableResults + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(dataGridViewOut); + Margin = new Padding(4, 5, 4, 5); + Name = "OutputTableResults"; + Size = new Size(581, 387); + ((System.ComponentModel.ISupportInitialize)dataGridViewOut).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridViewOut; + } +} diff --git a/Library15/OutputTableResults.cs b/Library15/OutputTableResults.cs new file mode 100644 index 0000000..fc9d2cc --- /dev/null +++ b/Library15/OutputTableResults.cs @@ -0,0 +1,88 @@ +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; +using Library15.Models; + +namespace Library15 +{ + public partial class OutputTableResults : UserControl + { + public OutputTableResults() + { + InitializeComponent(); + } + + public int SelectedRow + { + get => dataGridViewOut.SelectedRows.Count == 1 ? dataGridViewOut.SelectedRows[0].Index : -1; + set + { + if (value >= 0) + { + dataGridViewOut.Rows[value].Selected = true; + } + } + } + + public void ConfigureColumns(List Columns) + { + dataGridViewOut.ColumnCount = Columns.Count; + + for (int Index = 0; Index < Columns.Count; ++Index) + { + dataGridViewOut.Columns[Index].HeaderText = Columns[Index].Header; + dataGridViewOut.Columns[Index].Width = Columns[Index].Width; + dataGridViewOut.Columns[Index].Visible = Columns[Index].IsVisible; + dataGridViewOut.Columns[Index].Name = Columns[Index].Name; + } + } + + public void ClearGrid() + { + dataGridViewOut.Rows.Clear(); + } + + public T GetSelectedObject() where T : new() + { + T RetVal = new T(); + var Properties = typeof(T).GetProperties(); + + var Cells = dataGridViewOut.SelectedRows[0].Cells; + for (int Index = 0; Index < dataGridViewOut.ColumnCount; ++Index) + { + DataGridViewColumn Column = dataGridViewOut.Columns[Index]; + var Cell = Cells[Index]; + + var Property = Properties.FirstOrDefault(x => x.Name == Column.Name); + Property?.SetValue(RetVal, Cell.Value); + } + + return RetVal; + } + + public void InsertValue(T Object) + { + var Type = typeof(T); + var Properties = Type.GetProperties(); + + int NewRowIndex = dataGridViewOut.Rows.Add(); + + foreach (DataGridViewColumn Column in dataGridViewOut.Columns) + { + var Property = Properties.FirstOrDefault(x => x.Name == Column.Name); + if (Property == null) + throw new InvalidOperationException($"В типе {Type.Name} не найдено свойство с именем {Column.Name}"); + + var Value = Property.GetValue(Object); + dataGridViewOut.Rows[NewRowIndex].Cells[Column.Index].Value = Value; + } + } + } +} diff --git a/Library15/OutputTableResults.resx b/Library15/OutputTableResults.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Library15/OutputTableResults.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/Library15/UserControl1.Designer.cs b/Library15/UserControl1.Designer.cs new file mode 100644 index 0000000..91a8025 --- /dev/null +++ b/Library15/UserControl1.Designer.cs @@ -0,0 +1,73 @@ +namespace Library15 +{ + partial class UserControl1 + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + buttonLoad = new Button(); + pictureBoxAvatar = new PictureBox(); + ((System.ComponentModel.ISupportInitialize)pictureBoxAvatar).BeginInit(); + SuspendLayout(); + // + // buttonLoad + // + buttonLoad.Location = new Point(4, 197); + buttonLoad.Margin = new Padding(4, 5, 4, 5); + buttonLoad.Name = "buttonLoad"; + buttonLoad.Size = new Size(193, 38); + buttonLoad.TabIndex = 0; + buttonLoad.Text = "Загрузить"; + buttonLoad.UseVisualStyleBackColor = true; + // + // pictureBoxAvatar + // + pictureBoxAvatar.Location = new Point(4, 17); + pictureBoxAvatar.Margin = new Padding(4, 5, 4, 5); + pictureBoxAvatar.Name = "pictureBoxAvatar"; + pictureBoxAvatar.Size = new Size(193, 163); + pictureBoxAvatar.TabIndex = 2; + pictureBoxAvatar.TabStop = false; + // + // UserControl1 + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(pictureBoxAvatar); + Controls.Add(buttonLoad); + Margin = new Padding(4, 5, 4, 5); + Name = "UserControl1"; + Size = new Size(214, 240); + ((System.ComponentModel.ISupportInitialize)pictureBoxAvatar).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button buttonLoad; + private PictureBox pictureBoxAvatar; + } +} diff --git a/Library15/UserControl1.cs b/Library15/UserControl1.cs new file mode 100644 index 0000000..5b1b6c5 --- /dev/null +++ b/Library15/UserControl1.cs @@ -0,0 +1,63 @@ +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 Library15 +{ + public partial class UserControl1 : UserControl + { + private event EventHandler? _avatarChanged; + private event Action? _errorOccured; + public string Error { get; private set; } + public Image Avatar + { + get + { + return pictureBoxAvatar.Image; + } + set + { + pictureBoxAvatar.Image = value; + } + } + public event EventHandler AvatarChanged + { + add { _avatarChanged += value; } + remove { _avatarChanged -= value; } + } + public event Action AnErrorOccurred + { + add { _errorOccured += value; } + remove { _errorOccured -= value; } + } + public UserControl1() + { + InitializeComponent(); + Error = string.Empty; + } + private void ButtonLoad_Click(object sender, EventArgs e) + { + var ofd = new OpenFileDialog(); + if (ofd.ShowDialog() == DialogResult.OK) + { + try + { + pictureBoxAvatar.Image = + Image.FromFile(ofd.FileName); + _avatarChanged?.Invoke(this, e); + } + catch (Exception ex) + { + Error = ex.Message; + _errorOccured?.Invoke(); + } + } + } + } +} diff --git a/Library15/UserControl1.resx b/Library15/UserControl1.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Library15/UserControl1.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/WinFormsAppTest/Form1.Designer.cs b/WinFormsAppTest/Form1.Designer.cs new file mode 100644 index 0000000..8f3c257 --- /dev/null +++ b/WinFormsAppTest/Form1.Designer.cs @@ -0,0 +1,124 @@ +namespace WinFormsAppTest +{ + 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() + { + defaultList = new Library15.DefaultList(); + inputRealNumber = new Library15.InputRealNumber(); + outputTableResults = new Library15.OutputTableResults(); + CheckRealButton = new Button(); + ClearListButton = new Button(); + ClearDatagridButton = new Button(); + SuspendLayout(); + // + // defaultList + // + defaultList.Location = new Point(17, 20); + defaultList.Margin = new Padding(6, 8, 6, 8); + defaultList.Name = "defaultList"; + defaultList.SelectedItem = ""; + defaultList.Size = new Size(214, 250); + defaultList.TabIndex = 1; + defaultList.ItemSelected += defaultList_ItemSelected; + // + // inputRealNumber + // + inputRealNumber.Location = new Point(191, 20); + inputRealNumber.Margin = new Padding(6, 8, 6, 8); + inputRealNumber.Name = "inputRealNumber"; + inputRealNumber.Size = new Size(193, 168); + inputRealNumber.TabIndex = 2; + // + // outputTableResults + // + outputTableResults.Location = new Point(463, 20); + outputTableResults.Margin = new Padding(6, 8, 6, 8); + outputTableResults.Name = "outputTableResults"; + outputTableResults.SelectedRow = -1; + outputTableResults.Size = new Size(591, 418); + outputTableResults.TabIndex = 3; + // + // CheckRealButton + // + CheckRealButton.Location = new Point(192, 191); + CheckRealButton.Margin = new Padding(4, 5, 4, 5); + CheckRealButton.Name = "CheckRealButton"; + CheckRealButton.Size = new Size(192, 38); + CheckRealButton.TabIndex = 4; + CheckRealButton.Text = "Проверить"; + CheckRealButton.UseVisualStyleBackColor = true; + CheckRealButton.Click += CheckRealButton_Click_1; + // + // ClearListButton + // + ClearListButton.Location = new Point(17, 269); + ClearListButton.Margin = new Padding(4, 5, 4, 5); + ClearListButton.Name = "ClearListButton"; + ClearListButton.Size = new Size(148, 66); + ClearListButton.TabIndex = 5; + ClearListButton.Text = "Очистить"; + ClearListButton.UseVisualStyleBackColor = true; + ClearListButton.Click += ClearListButton_Click; + // + // ClearDatagridButton + // + ClearDatagridButton.Location = new Point(463, 409); + ClearDatagridButton.Margin = new Padding(4, 5, 4, 5); + ClearDatagridButton.Name = "ClearDatagridButton"; + ClearDatagridButton.Size = new Size(581, 38); + ClearDatagridButton.TabIndex = 6; + ClearDatagridButton.Text = "Очистить"; + ClearDatagridButton.UseVisualStyleBackColor = true; + ClearDatagridButton.Click += ClearDatagridButton_Click; + // + // Form1 + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1056, 592); + Controls.Add(ClearDatagridButton); + Controls.Add(ClearListButton); + Controls.Add(CheckRealButton); + Controls.Add(outputTableResults); + Controls.Add(inputRealNumber); + Controls.Add(defaultList); + Margin = new Padding(4, 5, 4, 5); + Name = "Form1"; + Text = "I love COP"; + ResumeLayout(false); + } + + #endregion + private Library15.DefaultList defaultList; + private Library15.InputRealNumber inputRealNumber; + private Library15.OutputTableResults outputTableResults; + private Button CheckRealButton; + private Button ClearListButton; + private Button ClearDatagridButton; + } +} \ No newline at end of file diff --git a/WinFormsAppTest/Form1.cs b/WinFormsAppTest/Form1.cs new file mode 100644 index 0000000..2b00688 --- /dev/null +++ b/WinFormsAppTest/Form1.cs @@ -0,0 +1,92 @@ +using Library15; +using Library15.Exceptions; + +namespace WinFormsAppTest +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + + InitializeDefaultList(); + InitializeInputRealNumber(); + InitializeOutputTableResults(); + } + + + private void InitializeDefaultList() + { + defaultList.SetItems("Sambuka2"); + } + + private void InitializeInputRealNumber() + { + inputRealNumber.DoubleValue = 322; + } + + private void InitializeOutputTableResults() + { + outputTableResults.ConfigureColumns(new List + { + new ColumnInfo("", 0, false, "Id"), + new ColumnInfo("Surname", 150, true, "Surname"), + new ColumnInfo("Name", 150, true, "Name"), + new ColumnInfo("Age", 50, true, "Age"), + }); + TestObject TestOB = new TestObject(1, "", "", 102); + TestObject TestOB2 = new TestObject(1, "", "", 19); + TestObject TestOB3 = new TestObject(1, "", "", 19); + + outputTableResults.InsertValue(TestOB); + outputTableResults.InsertValue(TestOB2); + outputTableResults.InsertValue(TestOB3); + + } + + private void defaultList_ItemSelected(object sender, EventArgs e) + { + MessageBox.Show(defaultList.SelectedItem); + } + + private void ClearListButton_Click(object sender, EventArgs e) + { + defaultList.ClearList(); + } + + private void PrintObjectButton_Click(object sender, EventArgs e) + { + var Test = outputTableResults.GetSelectedObject(); + MessageBox.Show(Test.ToString()); + } + + private void CheckRealButton_Click_1(object sender, EventArgs e) + { + try + { + double? Value = inputRealNumber.DoubleValue; + if (Value != null) + { + MessageBox.Show($" : {Value}"); + } + else + { + MessageBox.Show(" = null"); + } + } + catch (MalformedRealException ex) + { + MessageBox.Show(ex.Message); + } + catch (EmptyValueException ex) + { + MessageBox.Show(ex.Message); + } + } + + private void ClearDatagridButton_Click(object sender, EventArgs e) + { + outputTableResults.ClearGrid(); + } + } +} \ No newline at end of file diff --git a/WinFormsAppTest/Form1.resx b/WinFormsAppTest/Form1.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/WinFormsAppTest/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/WinFormsAppTest/Program.cs b/WinFormsAppTest/Program.cs new file mode 100644 index 0000000..6db5a46 --- /dev/null +++ b/WinFormsAppTest/Program.cs @@ -0,0 +1,17 @@ +namespace WinFormsAppTest +{ + 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/WinFormsAppTest/TestObject.cs b/WinFormsAppTest/TestObject.cs new file mode 100644 index 0000000..fbad234 --- /dev/null +++ b/WinFormsAppTest/TestObject.cs @@ -0,0 +1,30 @@ +namespace WinFormsAppTest +{ + public class TestObject + { + public int Id { get; set; } + public string Surname { get; set; } = string.Empty; + + public string Name { get; set; } = string.Empty; + + public int Age { get; set; } + + public TestObject() + { + } + + public TestObject(int Id, string Surname, string Name, int Age) + { + this.Id = Id; + this.Surname = Surname; + this.Name = Name; + this.Age = Age; + } + + public override string ToString() + { + return $"[{Id}] {Surname} {Name}. Возраст: {Age}"; + } + + } +} diff --git a/WinFormsAppTest/WinFormsAppDone.csproj b/WinFormsAppTest/WinFormsAppDone.csproj new file mode 100644 index 0000000..4bb4c0f --- /dev/null +++ b/WinFormsAppTest/WinFormsAppDone.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + \ No newline at end of file diff --git a/WindowsFormsTest/App.config b/WindowsFormsTest/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/WindowsFormsTest/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/WindowsFormsTest/Form1.Designer.cs b/WindowsFormsTest/Form1.Designer.cs new file mode 100644 index 0000000..4a4be6e --- /dev/null +++ b/WindowsFormsTest/Form1.Designer.cs @@ -0,0 +1,40 @@ +namespace WindowsFormsTest +{ + partial class Form1 + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором форм Windows + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "Form1"; + } + + #endregion + } +} + diff --git a/WindowsFormsTest/Form1.cs b/WindowsFormsTest/Form1.cs new file mode 100644 index 0000000..15cf409 --- /dev/null +++ b/WindowsFormsTest/Form1.cs @@ -0,0 +1,20 @@ +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 WindowsFormsTest +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + } +} diff --git a/WindowsFormsTest/Program.cs b/WindowsFormsTest/Program.cs new file mode 100644 index 0000000..2ee17d4 --- /dev/null +++ b/WindowsFormsTest/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WindowsFormsTest +{ + internal static class Program + { + /// + /// Главная точка входа для приложения. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/WindowsFormsTest/Properties/AssemblyInfo.cs b/WindowsFormsTest/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..78840ba --- /dev/null +++ b/WindowsFormsTest/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Общие сведения об этой сборке предоставляются следующим набором +// набора атрибутов. Измените значения этих атрибутов для изменения сведений, +// связанных со сборкой. +[assembly: AssemblyTitle("WindowsFormsTest")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WindowsFormsTest")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми +// для компонентов COM. Если необходимо обратиться к типу в этой сборке через +// COM, следует установить атрибут ComVisible в TRUE для этого типа. +[assembly: ComVisible(false)] + +// Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM +[assembly: Guid("fa527d70-da4c-4a9d-9e06-25334526a68c")] + +// Сведения о версии сборки состоят из указанных ниже четырех значений: +// +// Основной номер версии +// Дополнительный номер версии +// Номер сборки +// Редакция +// +// Можно задать все значения или принять номера сборки и редакции по умолчанию +// используя "*", как показано ниже: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/WindowsFormsTest/Properties/Resources.Designer.cs b/WindowsFormsTest/Properties/Resources.Designer.cs new file mode 100644 index 0000000..471c8b4 --- /dev/null +++ b/WindowsFormsTest/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программным средством. +// Версия среды выполнения: 4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильному поведению и будут утрачены, если +// код создан повторно. +// +//------------------------------------------------------------------------------ + +namespace WindowsFormsTest.Properties +{ + + + /// + /// Класс ресурсов со строгим типом для поиска локализованных строк и пр. + /// + // Этот класс был автоматически создан при помощи StronglyTypedResourceBuilder + // класс с помощью таких средств, как ResGen или Visual Studio. + // Для добавления или удаления члена измените файл .ResX, а затем перезапустите ResGen + // с параметром /str или заново постройте свой VS-проект. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Возврат кэшированного экземпляра ResourceManager, используемого этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WindowsFormsTest.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Переопределяет свойство CurrentUICulture текущего потока для всех + /// подстановки ресурсов с помощью этого класса ресурсов со строгим типом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/WindowsFormsTest/Properties/Resources.resx b/WindowsFormsTest/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/WindowsFormsTest/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WindowsFormsTest/Properties/Settings.Designer.cs b/WindowsFormsTest/Properties/Settings.Designer.cs new file mode 100644 index 0000000..1f8c51e --- /dev/null +++ b/WindowsFormsTest/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace WindowsFormsTest.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/WindowsFormsTest/Properties/Settings.settings b/WindowsFormsTest/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/WindowsFormsTest/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/WindowsFormsTest/WindowsFormsTest.csproj b/WindowsFormsTest/WindowsFormsTest.csproj new file mode 100644 index 0000000..56dec3f --- /dev/null +++ b/WindowsFormsTest/WindowsFormsTest.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {FA527D70-DA4C-4A9D-9E06-25334526A68C} + WinExe + WindowsFormsTest + WindowsFormsTest + v4.8 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file