3 элемента, но 2 и 3 подлатать
This commit is contained in:
parent
407af44b84
commit
8cb26eeb80
57
CustomCheckedListBox.Designer.cs
generated
Normal file
57
CustomCheckedListBox.Designer.cs
generated
Normal file
@ -0,0 +1,57 @@
|
||||
namespace CustomsComponentsVar2
|
||||
{
|
||||
partial class CustomCheckedListBox
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
checkedListBox = new CheckedListBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// checkedListBox
|
||||
//
|
||||
checkedListBox.Dock = DockStyle.Fill;
|
||||
checkedListBox.FormattingEnabled = true;
|
||||
checkedListBox.Location = new Point(0, 0);
|
||||
checkedListBox.Name = "checkedListBox";
|
||||
checkedListBox.Size = new Size(262, 446);
|
||||
checkedListBox.TabIndex = 0;
|
||||
//
|
||||
// CustomCheckedListBox
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 19F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(checkedListBox);
|
||||
Name = "CustomCheckedListBox";
|
||||
Size = new Size(262, 446);
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private CheckedListBox checkedListBox;
|
||||
}
|
||||
}
|
69
CustomCheckedListBox.cs
Normal file
69
CustomCheckedListBox.cs
Normal file
@ -0,0 +1,69 @@
|
||||
namespace CustomsComponentsVar2;
|
||||
|
||||
public partial class CustomCheckedListBox : UserControl
|
||||
{
|
||||
private event EventHandler? _selectedChanged;
|
||||
public CustomCheckedListBox()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public string SelectedElement
|
||||
{
|
||||
get
|
||||
{
|
||||
if (checkedListBox.Items.Count == 0 || checkedListBox.Items == null)
|
||||
{
|
||||
return String.Empty;
|
||||
}
|
||||
return checkedListBox.Items.ToString();
|
||||
}
|
||||
set
|
||||
{
|
||||
if (checkedListBox.Items.Contains(value))
|
||||
{
|
||||
checkedListBox.SelectedItem = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавить элементы
|
||||
/// </summary>
|
||||
/// <param name="s"></param>
|
||||
public void addElements(List<string> s)
|
||||
{
|
||||
checkedListBox.Items.Clear();
|
||||
checkedListBox.Items.AddRange(s.ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Выбран элемент
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void onItemCheck(object sender, ItemCheckEventArgs e)
|
||||
{
|
||||
_selectedChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение индекса выбранного элемента
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void checkedListBox_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (checkedListBox.CheckedItems.Count > 1)
|
||||
{
|
||||
foreach (int index in checkedListBox.CheckedIndices)
|
||||
{
|
||||
if (index != checkedListBox.SelectedIndex)
|
||||
{
|
||||
checkedListBox.SetItemChecked(index, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
_selectedChanged?.Invoke(sender, e);
|
||||
}
|
||||
}
|
120
CustomCheckedListBox.resx
Normal file
120
CustomCheckedListBox.resx
Normal 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>
|
10
CustomComponentsVar2.csproj
Normal file
10
CustomComponentsVar2.csproj
Normal file
@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
68
CustomDateTimePicker.Designer.cs
generated
Normal file
68
CustomDateTimePicker.Designer.cs
generated
Normal file
@ -0,0 +1,68 @@
|
||||
namespace CustomsComponentsVar2
|
||||
{
|
||||
partial class CustomDateTimePicker
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
dateTimePicker = new DateTimePicker();
|
||||
label1 = new Label();
|
||||
SuspendLayout();
|
||||
//
|
||||
// dateTimePicker
|
||||
//
|
||||
dateTimePicker.Location = new Point(121, 8);
|
||||
dateTimePicker.Name = "dateTimePicker";
|
||||
dateTimePicker.Size = new Size(235, 26);
|
||||
dateTimePicker.TabIndex = 0;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(7, 11);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(106, 19);
|
||||
label1.TabIndex = 1;
|
||||
label1.Text = "Выберите дату:";
|
||||
//
|
||||
// CustomDateTimePicker
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 19F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(label1);
|
||||
Controls.Add(dateTimePicker);
|
||||
Name = "CustomDateTimePicker";
|
||||
Size = new Size(365, 42);
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DateTimePicker dateTimePicker;
|
||||
private Label label1;
|
||||
}
|
||||
}
|
39
CustomDateTimePicker.cs
Normal file
39
CustomDateTimePicker.cs
Normal file
@ -0,0 +1,39 @@
|
||||
namespace CustomsComponentsVar2;
|
||||
|
||||
public partial class CustomDateTimePicker : UserControl
|
||||
{
|
||||
public CustomDateTimePicker()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public event EventHandler<DateTime> _dateChanged;
|
||||
public DateTime dateStart;
|
||||
public DateTime dateEnd;
|
||||
public DateTime date
|
||||
{
|
||||
get
|
||||
{
|
||||
if (dateStart == null || dateEnd == null)
|
||||
{
|
||||
throw new RangeNotSetException("Не задан диапазон.");
|
||||
}
|
||||
if (date < dateStart && date > dateEnd)
|
||||
{
|
||||
throw new ValueNotInRangeException("Значение не входит в диапазон");
|
||||
}
|
||||
return date;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value >= dateStart && value <= dateEnd)
|
||||
{
|
||||
date = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void dateChanged(DateTime date)
|
||||
{
|
||||
_dateChanged?.Invoke(this, date);
|
||||
}
|
||||
}
|
120
CustomDateTimePicker.resx
Normal file
120
CustomDateTimePicker.resx
Normal 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>
|
58
CustomTreeView.Designer.cs
generated
Normal file
58
CustomTreeView.Designer.cs
generated
Normal file
@ -0,0 +1,58 @@
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace CustomsComponentsVar2
|
||||
{
|
||||
partial class CustomTreeView
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
treeView = new TreeView();
|
||||
SuspendLayout();
|
||||
//
|
||||
// treeView
|
||||
//
|
||||
treeView.Dock = DockStyle.Fill;
|
||||
treeView.Location = new Point(0, 0);
|
||||
treeView.Name = "treeView";
|
||||
treeView.Size = new Size(328, 360);
|
||||
treeView.TabIndex = 0;
|
||||
//
|
||||
// CustomTreeView
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 19F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(treeView);
|
||||
Name = "CustomTreeView";
|
||||
Size = new Size(328, 360);
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private TreeView treeView;
|
||||
}
|
||||
}
|
140
CustomTreeView.cs
Normal file
140
CustomTreeView.cs
Normal file
@ -0,0 +1,140 @@
|
||||
namespace CustomsComponentsVar2;
|
||||
|
||||
public partial class CustomTreeView: UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Иерархия дерева по полям класса
|
||||
/// </summary>
|
||||
private List<string> hierarchy;
|
||||
/// <summary>
|
||||
/// Список полей, для которых обязательно создаем новыую ветку (например, ФИО, на случай полных однофамильцев)
|
||||
/// </summary>
|
||||
private Dictionary<string, bool> newBranch;
|
||||
public int SelectedIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return SelectedIndex;
|
||||
}
|
||||
set
|
||||
{
|
||||
SelectedIndex = value;
|
||||
}
|
||||
}
|
||||
public CustomTreeView()
|
||||
{
|
||||
InitializeComponent();
|
||||
hierarchy = new List<string>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Устанавливает иерархию по полям класса, начиная с главного
|
||||
/// </summary>
|
||||
/// <param name="hierarchy"></param>
|
||||
/// <param name="newBranch"></param>
|
||||
public void setHierarchy(List<string> hierarchy, Dictionary<string, bool> newBranch)
|
||||
{
|
||||
this.hierarchy = hierarchy;
|
||||
this.newBranch = newBranch;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Строит дерево на основе полученных элементов
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="elements"></param>
|
||||
public void build<T>(List<T> elements)
|
||||
{
|
||||
foreach (var el in elements)
|
||||
{
|
||||
add(el, hierarchy, treeView.Nodes, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Рекурсивно добавляет узлы в дерево
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="el"></param>
|
||||
/// <param name="hierarchy"></param>
|
||||
/// <param name="nodes"></param>
|
||||
/// <param name="level"></param>
|
||||
private void add<T>(T el, List<string> hierarchy, TreeNodeCollection nodes, int level)
|
||||
{
|
||||
// если превышено количество уровней в иерархии
|
||||
if (level >= hierarchy.Count)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// находим свойство (на основе иерархии) – извлекаем значение
|
||||
string property = hierarchy[level];
|
||||
string propertyValue = el.GetType().GetProperty(property)?.GetValue(el)?.ToString() ?? string.Empty;
|
||||
|
||||
// ищем, есть ли уже узел с таким названием
|
||||
TreeNode foundNode = null;
|
||||
foreach (TreeNode node in nodes)
|
||||
{
|
||||
if (node.Text == propertyValue)
|
||||
{
|
||||
foundNode = node;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// если не найден ИЛИ указано, что нужно создать новый узел, то добавляем новый узел
|
||||
if (foundNode == null || newBranch.ContainsKey(property) && newBranch[property])
|
||||
{
|
||||
foundNode = nodes.Add(propertyValue);
|
||||
}
|
||||
|
||||
// шаг на уровень глубже
|
||||
add(el, hierarchy, foundNode.Nodes, level + 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// получение выбранного элемента по индексу (с рефлексией)
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
public T getSelected<T>() where T : new()
|
||||
{
|
||||
if (SelectedIndex >= 0 && SelectedIndex < treeView.Nodes.Count)
|
||||
{
|
||||
TreeNode node = treeView.Nodes[SelectedIndex];
|
||||
// если последний уровень
|
||||
if (node.Level == hierarchy.Count)
|
||||
{
|
||||
T el = new T();
|
||||
setProperties(el, node, node.Level);
|
||||
return el;
|
||||
}
|
||||
}
|
||||
return default(T);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// получение значений свойств элемента по узлам
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="el"></param>
|
||||
/// <param name="node"></param>
|
||||
/// <param name="level"></param>
|
||||
private void setProperties<T>(T el, TreeNode node, int level)
|
||||
{
|
||||
if (hierarchy.Count >= level)
|
||||
{
|
||||
var property = hierarchy[level];
|
||||
var propertyValue = typeof(T).GetProperty(property);
|
||||
if (propertyValue != null)
|
||||
{
|
||||
propertyValue.SetValue(el, node.Text);
|
||||
}
|
||||
}
|
||||
|
||||
if (node.Parent != null)
|
||||
{
|
||||
setProperties(el, node.Parent, level - 1);
|
||||
}
|
||||
}
|
||||
}
|
120
CustomTreeView.resx
Normal file
120
CustomTreeView.resx
Normal 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>
|
31
CustomsComponentsVar2.sln
Normal file
31
CustomsComponentsVar2.sln
Normal file
@ -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("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomComponentsVar2", "CustomComponentsVar2.csproj", "{02BF1C07-1A86-40B3-84AF-EA9344B5382E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsApp", "..\WinFormsApp\WinFormsApp.csproj", "{EA6E87EE-31C6-4D6F-9A1A-DAC6F3F05E45}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{02BF1C07-1A86-40B3-84AF-EA9344B5382E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{02BF1C07-1A86-40B3-84AF-EA9344B5382E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{02BF1C07-1A86-40B3-84AF-EA9344B5382E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{02BF1C07-1A86-40B3-84AF-EA9344B5382E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{EA6E87EE-31C6-4D6F-9A1A-DAC6F3F05E45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{EA6E87EE-31C6-4D6F-9A1A-DAC6F3F05E45}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EA6E87EE-31C6-4D6F-9A1A-DAC6F3F05E45}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{EA6E87EE-31C6-4D6F-9A1A-DAC6F3F05E45}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {371DADAB-9A54-4924-95A5-295AF029F39E}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
9
Exception/RangeNotSetException.cs
Normal file
9
Exception/RangeNotSetException.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace CustomsComponentsVar2
|
||||
{
|
||||
public class RangeNotSetException : System.Exception
|
||||
{
|
||||
public RangeNotSetException() { }
|
||||
|
||||
public RangeNotSetException(string message) : base(message){ }
|
||||
}
|
||||
}
|
8
Exception/ValueNotInRangeException.cs
Normal file
8
Exception/ValueNotInRangeException.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace CustomsComponentsVar2
|
||||
{
|
||||
public class ValueNotInRangeException : System.Exception
|
||||
{
|
||||
public ValueNotInRangeException() { }
|
||||
public ValueNotInRangeException(string message) : base(message){ }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user