Готовая 1 лаба)

This commit is contained in:
Extrimal 2024-09-09 22:02:46 +04:00
parent 760641787f
commit cd207e87e6
20 changed files with 1378 additions and 0 deletions

View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34622.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreateVisualComponent", "CreateVisualComponent\CreateVisualComponent.csproj", "{97D95702-D830-4B2E-B310-7E8586859473}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsTest", "WinFormsTest\WinFormsTest.csproj", "{598218F4-A9A1-49E9-9DE9-D145C618D65E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{97D95702-D830-4B2E-B310-7E8586859473}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{97D95702-D830-4B2E-B310-7E8586859473}.Debug|Any CPU.Build.0 = Debug|Any CPU
{97D95702-D830-4B2E-B310-7E8586859473}.Release|Any CPU.ActiveCfg = Release|Any CPU
{97D95702-D830-4B2E-B310-7E8586859473}.Release|Any CPU.Build.0 = Release|Any CPU
{598218F4-A9A1-49E9-9DE9-D145C618D65E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{598218F4-A9A1-49E9-9DE9-D145C618D65E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{598218F4-A9A1-49E9-9DE9-D145C618D65E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{598218F4-A9A1-49E9-9DE9-D145C618D65E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CAD1F4CD-D5FF-4D0B-9B14-A3E41FECD290}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CreateVisualComponent
{
public class ColumnsConfiguratoin
{
public int ColumnsCount { get; set; }
public string[] ColumnName { get; set; }
public int[] Width { get; set; }
public bool[] Visible { get; set; }
public string[] PropertiesObject { get; set; }
}
}

View File

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CreateVisualComponent.Exceptions
{
public class IncorrectFillingException : Exception
{
public IncorrectFillingException() { }
public IncorrectFillingException(string message) : base(message) { }
public IncorrectFillingException(string message, Exception innerException) : base(message, innerException) { }
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CreateVisualComponent.Exceptions
{
public class NotFilledException : Exception
{
public NotFilledException() { }
public NotFilledException(string message) : base(message) { }
public NotFilledException(string message, Exception inner) : base(message, inner) { }
}
}

View File

@ -0,0 +1,69 @@
namespace CreateVisualComponent
{
partial class InputComponent
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
textBoxDate = new TextBox();
checkBoxDate = new CheckBox();
SuspendLayout();
//
// textBoxDate
//
textBoxDate.Location = new Point(37, 20);
textBoxDate.Name = "textBoxDate";
textBoxDate.Size = new Size(168, 27);
textBoxDate.TabIndex = 1;
textBoxDate.TextChanged += TextBoxDate_TextChanged;
//
// checkBoxDate
//
checkBoxDate.AutoSize = true;
checkBoxDate.Location = new Point(13, 26);
checkBoxDate.Name = "checkBoxDate";
checkBoxDate.Size = new Size(18, 17);
checkBoxDate.TabIndex = 2;
checkBoxDate.UseVisualStyleBackColor = true;
checkBoxDate.CheckedChanged += CheckBoxDate_CheckedChanged;
//
// InputComponent
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(checkBoxDate);
Controls.Add(textBoxDate);
Name = "InputComponent";
Size = new Size(225, 68);
ResumeLayout(false);
PerformLayout();
}
#endregion
private TextBox textBoxDate;
private CheckBox checkBoxDate;
}
}

View File

@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using CreateVisualComponent.Exceptions;
namespace CreateVisualComponent
{
public partial class InputComponent : UserControl
{
public EventHandler? _changeEvent;
public EventHandler? _checkBoxEvent;
public Exception? Error;
public InputComponent()
{
InitializeComponent();
}
public DateTime? Value
{
get
{
if (!checkBoxDate.Checked)
{
if (string.IsNullOrEmpty(textBoxDate.Text))
{
throw new NotFilledException("The textbox is empty, fill it in or click on the checkbox!");
}
if (DateTime.TryParseExact(textBoxDate.Text, "dd/MM/yyyy", null, DateTimeStyles.None, out DateTime parsedDate))
{
return parsedDate;
}
else
{
throw new IncorrectFillingException(textBoxDate.Text + " incorrect date!");
}
}
return null;
}
set
{
if (value is null)
{
checkBoxDate.Checked = true;
}
else
{
textBoxDate.Text = value?.ToString("dd/MM/yyyy");
checkBoxDate.Checked = false;
}
}
}
public event EventHandler CheckBoxEvent
{
add { _checkBoxEvent += value; }
remove { _checkBoxEvent += value; }
}
private void TextBoxDate_TextChanged(object sender, EventArgs e)
{
_changeEvent?.Invoke(sender, e);
}
private void CheckBoxDate_CheckedChanged(object sender, EventArgs e)
{
textBoxDate.Enabled = !checkBoxDate.Checked;
_checkBoxEvent?.Invoke(sender, e);
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,70 @@
namespace CreateVisualComponent
{
partial class ListOutputComponent
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
dataGridViewTable = new DataGridView();
((System.ComponentModel.ISupportInitialize)dataGridViewTable).BeginInit();
SuspendLayout();
//
// dataGridViewTable
//
dataGridViewTable.AllowUserToAddRows = false;
dataGridViewTable.AllowUserToDeleteRows = false;
dataGridViewTable.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
dataGridViewTable.BackgroundColor = SystemColors.ButtonFace;
dataGridViewTable.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewTable.GridColor = SystemColors.ActiveCaptionText;
dataGridViewTable.Location = new Point(0, 0);
dataGridViewTable.MultiSelect = false;
dataGridViewTable.Name = "dataGridViewTable";
dataGridViewTable.ReadOnly = true;
dataGridViewTable.RowHeadersVisible = false;
dataGridViewTable.RowHeadersWidth = 51;
dataGridViewTable.RowTemplate.Height = 29;
dataGridViewTable.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewTable.ShowEditingIcon = false;
dataGridViewTable.Size = new Size(620, 443);
dataGridViewTable.TabIndex = 0;
//
// ListOutputComponent
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(dataGridViewTable);
Name = "ListOutputComponent";
Size = new Size(620, 443);
((System.ComponentModel.ISupportInitialize)dataGridViewTable).EndInit();
ResumeLayout(false);
}
#endregion
private DataGridView dataGridViewTable;
}
}

View File

@ -0,0 +1,107 @@
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 CreateVisualComponent
{
public partial class ListOutputComponent : UserControl
{
public ListOutputComponent()
{
InitializeComponent();
}
public int SelectedRow
{
get { return dataGridViewTable.SelectedRows[0].Index; }
set
{
if (dataGridViewTable.SelectedRows.Count <= value || value < 0)
throw new ArgumentException(string.Format("{0} is an invalid row index.", value));
else
{
dataGridViewTable.ClearSelection();
dataGridViewTable.Rows[value].Selected = true;
}
}
}
public void ClearDataGrid()
{
dataGridViewTable.DataSource = null;
dataGridViewTable.Rows.Clear();
}
public void ConfigColumn(ColumnsConfiguratoin columnsData)
{
dataGridViewTable.ColumnCount = columnsData.ColumnsCount;
for (int i = 0; i < columnsData.ColumnsCount; i++)
{
dataGridViewTable.Columns[i].Name = columnsData.ColumnName[i];
dataGridViewTable.Columns[i].Width = columnsData.Width[i];
dataGridViewTable.Columns[i].Visible = columnsData.Visible[i];
dataGridViewTable.Columns[i].DataPropertyName = columnsData.PropertiesObject[i];
}
}
public T GetSelectedObjectInRow<T>() where T : class, new()
{
T val = new();
var propertiesObj = typeof(T).GetProperties();
foreach (var property in propertiesObj)
{
bool propIsExist = false;
int columnIndex = 0;
for (; columnIndex < dataGridViewTable.Columns.Count; columnIndex++)
{
if (dataGridViewTable.Columns[columnIndex].DataPropertyName.ToString() == property.Name)
{
propIsExist = true;
break;
}
}
if (propIsExist)
{
object value = dataGridViewTable.SelectedRows[0].Cells[columnIndex].Value;
Type propertyType = property.PropertyType;
bool isNullable = Nullable.GetUnderlyingType(propertyType) != null;
if (isNullable)
{
propertyType = Nullable.GetUnderlyingType(propertyType);
}
if (value != DBNull.Value)
{
property.SetValue(val, Convert.ChangeType(value, propertyType));
}
else if (isNullable)
{
property.SetValue(val, null);
}
}
}
return val;
}
public void AddItem<T>(T item, int RowIndex, int ColumnIndex)
{
if (item == null)
return;
string propertyName = dataGridViewTable.Columns[ColumnIndex].DataPropertyName.ToString();
string? value = item.GetType().GetProperty(propertyName)?.GetValue(item)?.ToString();
if (RowIndex >= dataGridViewTable.Rows.Count)
{
dataGridViewTable.RowCount = RowIndex + 1;
}
dataGridViewTable.Rows[RowIndex].Cells[ColumnIndex].Value = value;
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,59 @@
namespace CreateVisualComponent
{
partial class SelectionComponent
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
listBoxSimple = new ListBox();
SuspendLayout();
//
// listBoxSimple
//
listBoxSimple.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
listBoxSimple.FormattingEnabled = true;
listBoxSimple.ItemHeight = 20;
listBoxSimple.Location = new Point(0, 0);
listBoxSimple.Name = "listBoxSimple";
listBoxSimple.Size = new Size(207, 204);
listBoxSimple.TabIndex = 0;
listBoxSimple.SelectedIndexChanged += ListBoxSimple_SelectedIndexChanged;
//
// SelectionComponent
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(listBoxSimple);
Name = "SelectionComponent";
Size = new Size(207, 204);
ResumeLayout(false);
}
#endregion
private ListBox listBoxSimple;
}
}

View File

@ -0,0 +1,60 @@
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 CreateVisualComponent
{
public partial class SelectionComponent : UserControl
{
private EventHandler? _changeEvent;
public ListBox.ObjectCollection Items => listBoxSimple.Items;
public SelectionComponent()
{
InitializeComponent();
}
public event EventHandler ChangeEvent
{
add
{
_changeEvent += value;
}
remove
{
_changeEvent -= value;
}
}
public string SelectedElement
{
get
{
return (listBoxSimple.SelectedIndex != -1 && listBoxSimple.SelectedItem != null)
? listBoxSimple.SelectedItem.ToString()
: string.Empty;
}
set
{
if (!string.IsNullOrEmpty(value))
{
int index = listBoxSimple.FindString(value);
if (index == -1) return;
listBoxSimple.SetSelected(index, true);
}
}
}
private void ListBoxSimple_SelectedIndexChanged(object sender, EventArgs e)
{
_changeEvent?.Invoke(sender, e);
}
public void Clear()
{
listBoxSimple.Items.Clear();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WinFormsTest
{
public class Delivery
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string DeliveryStatus { get; set; } = string.Empty;
public int? CountProduct { get; set; }
public Delivery(int id, string name, string statusd, int productD) {
Id = id;
Name = name;
DeliveryStatus = statusd;
CountProduct = productD;
}
public Delivery() { }
}
}

View File

@ -0,0 +1,181 @@
namespace WinFormsTest
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
SelectionComponent = new CreateVisualComponent.SelectionComponent();
buttonLoad = new Button();
buttonClear = new Button();
InputComponent = new CreateVisualComponent.InputComponent();
buttonSetDate = new Button();
buttonGetDate = new Button();
textBoxEvent = new TextBox();
ListOutputComponent = new CreateVisualComponent.ListOutputComponent();
buttonClearTable = new Button();
buttonShowTable = new Button();
buttonGet = new Button();
SuspendLayout();
//
// SelectionComponent
//
SelectionComponent.Location = new Point(12, 12);
SelectionComponent.Name = "SelectionComponent";
SelectionComponent.SelectedElement = "";
SelectionComponent.Size = new Size(205, 195);
SelectionComponent.TabIndex = 0;
SelectionComponent.ChangeEvent += SelectionComponent_ChangeEvent;
//
// buttonLoad
//
buttonLoad.Location = new Point(12, 213);
buttonLoad.Name = "buttonLoad";
buttonLoad.Size = new Size(94, 29);
buttonLoad.TabIndex = 1;
buttonLoad.Text = "Load";
buttonLoad.UseVisualStyleBackColor = true;
buttonLoad.Click += ButtonListLoad_Click;
//
// buttonClear
//
buttonClear.Location = new Point(123, 213);
buttonClear.Name = "buttonClear";
buttonClear.Size = new Size(94, 29);
buttonClear.TabIndex = 2;
buttonClear.Text = "Clear";
buttonClear.UseVisualStyleBackColor = true;
buttonClear.Click += ButtonListClear_Click;
//
// InputComponent
//
InputComponent.Location = new Point(0, 268);
InputComponent.Name = "InputComponent";
InputComponent.Size = new Size(217, 67);
InputComponent.TabIndex = 3;
InputComponent.CheckBoxEvent += InputComponent_CheckBoxEvent;
//
// buttonSetDate
//
buttonSetDate.Location = new Point(12, 332);
buttonSetDate.Name = "buttonSetDate";
buttonSetDate.Size = new Size(94, 29);
buttonSetDate.TabIndex = 4;
buttonSetDate.Text = "Set";
buttonSetDate.UseVisualStyleBackColor = true;
buttonSetDate.Click += ButtonSet_Click;
//
// buttonGetDate
//
buttonGetDate.Location = new Point(123, 332);
buttonGetDate.Name = "buttonGetDate";
buttonGetDate.Size = new Size(94, 29);
buttonGetDate.TabIndex = 5;
buttonGetDate.Text = "Get";
buttonGetDate.UseVisualStyleBackColor = true;
buttonGetDate.Click += ButtonGet_Click;
//
// textBoxEvent
//
textBoxEvent.Location = new Point(52, 378);
textBoxEvent.Name = "textBoxEvent";
textBoxEvent.Size = new Size(125, 27);
textBoxEvent.TabIndex = 6;
//
// ListOutputComponent
//
ListOutputComponent.Location = new Point(268, 12);
ListOutputComponent.Name = "ListOutputComponent";
ListOutputComponent.Size = new Size(520, 230);
ListOutputComponent.TabIndex = 7;
//
// buttonClearTable
//
buttonClearTable.Location = new Point(480, 259);
buttonClearTable.Name = "buttonClearTable";
buttonClearTable.Size = new Size(94, 50);
buttonClearTable.TabIndex = 9;
buttonClearTable.Text = "Crear";
buttonClearTable.UseVisualStyleBackColor = true;
buttonClearTable.Click += ButtonClearTable_Click;
//
// buttonShowTable
//
buttonShowTable.Location = new Point(329, 259);
buttonShowTable.Name = "buttonShowTable";
buttonShowTable.Size = new Size(94, 50);
buttonShowTable.TabIndex = 10;
buttonShowTable.Text = "Show";
buttonShowTable.UseVisualStyleBackColor = true;
buttonShowTable.Click += ButtonShowTable_Click;
//
// buttonGet
//
buttonGet.Location = new Point(627, 259);
buttonGet.Name = "buttonGet";
buttonGet.Size = new Size(94, 50);
buttonGet.TabIndex = 11;
buttonGet.Text = "Получить строку";
buttonGet.UseVisualStyleBackColor = true;
buttonGet.Click += ButtonGetString_Click;
//
// Form1
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(buttonGet);
Controls.Add(buttonShowTable);
Controls.Add(buttonClearTable);
Controls.Add(ListOutputComponent);
Controls.Add(textBoxEvent);
Controls.Add(buttonGetDate);
Controls.Add(buttonSetDate);
Controls.Add(InputComponent);
Controls.Add(buttonClear);
Controls.Add(buttonLoad);
Controls.Add(SelectionComponent);
Name = "Form1";
Text = "Form1";
ResumeLayout(false);
PerformLayout();
}
#endregion
private CreateVisualComponent.SelectionComponent SelectionComponent;
private Button buttonLoad;
private Button buttonClear;
private CreateVisualComponent.InputComponent InputComponent;
private Button buttonSetDate;
private Button buttonGetDate;
private TextBox textBoxEvent;
private CreateVisualComponent.ListOutputComponent ListOutputComponent;
private Button buttonClearTable;
private Button buttonShowTable;
private Button buttonGet;
}
}

View File

@ -0,0 +1,130 @@
using CreateVisualComponent;
using Microsoft.VisualBasic.Devices;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Header;
namespace WinFormsTest
{
public partial class Form1 : Form
{
private bool EmptyFill = false;
int count = 1;
public Form1()
{
InitializeComponent();
CreateList();
}
private void CreateList()
{
for (int i = 0; i < 10; i++)
{
SelectionComponent.Items.Add($"Food ¹{i}");
}
}
private void ButtonListClear_Click(object sender, EventArgs e)
{
SelectionComponent.Clear();
}
private void ButtonListLoad_Click(object sender, EventArgs e)
{
SelectionComponent.Clear();
CreateList();
}
private void SelectionComponent_ChangeEvent(object sender, EventArgs e)
{
object? selectedItem = SelectionComponent.SelectedElement;
MessageBox.Show($"Change selected {selectedItem?.ToString()}");
}
private void InputComponent_CheckBoxEvent(object sender, EventArgs e)
{
count++;
if (count % 2 == 0)
{
textBoxEvent.Text = "null";
}
else
{
textBoxEvent.Text = "not null";
}
}
private void ButtonGet_Click(object sender, EventArgs e)
{
try
{
if (InputComponent.Value == null)
{
MessageBox.Show($"Pressed Checkbox");
}
else
{
MessageBox.Show($"Date: {InputComponent.Value}");
}
}
catch (Exception ex)
{
MessageBox.Show($"Error: {ex.Message}");
}
}
private void ButtonSet_Click(object sender, EventArgs e)
{
if (EmptyFill)
{
InputComponent.Value = DateTime.Now;
}
else
{
InputComponent.Value = null;
}
EmptyFill = !EmptyFill;
}
readonly List<Delivery> delivers = new()
{
new Delivery { Id = 0, Name = "Ðàõìàäæîí", DeliveryStatus = "Âûäàí", CountProduct = 5 },
new Delivery { Id = 1, Name = "Ãóçáûç", DeliveryStatus = "Âûäàí", CountProduct = 3 },
new Delivery { Id = 2, Name = "Àëåêñàíäð", DeliveryStatus = "Ñôîðìèðîâàíî", CountProduct = 7 },
new Delivery { Id = 3, Name = "Èíàêåíòèé", DeliveryStatus = "Â ïóòè", CountProduct = 4 },
new Delivery { Id = 4, Name = "Òàòüÿíà", DeliveryStatus = "Ñôîðìèðîâàíî", CountProduct = 5 }
};
private void CreateTable()
{
ListOutputComponent.ConfigColumn(new()
{
ColumnsCount = 4,
ColumnName = new string[] { "Id", "Name", "DeliveryStatus", "CountProduct" },
Width = new int[] { 10, 150, 250, 200 },
Visible = new bool[] { false, true, true, true, true },
PropertiesObject = new string[] { "Id", "Name", "DeliveryStatus", "CountProduct" }
});
foreach (Delivery delivery in delivers)
{
for (int i = 0; i < 4; i++)
{
ListOutputComponent.AddItem(delivery, delivery.Id, i);
ListOutputComponent.Update();
}
}
}
private void ButtonShowTable_Click(object sender, EventArgs e)
{
CreateTable();
}
private void ButtonClearTable_Click(object sender, EventArgs e)
{
ListOutputComponent.ClearDataGrid();
}
private void ButtonGetString_Click(object sender, EventArgs e)
{
Delivery? delivery = ListOutputComponent.GetSelectedObjectInRow<Delivery>();
if (delivery is null) return;
MessageBox.Show($"{delivery.Id}-{delivery.Name}-{delivery.DeliveryStatus}-{delivery.CountProduct}");
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,17 @@
namespace WinFormsTest
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[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());
}
}
}

View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\CreateVisualComponent\CreateVisualComponent.csproj" />
</ItemGroup>
</Project>