тестовый компонент работает
This commit is contained in:
parent
78e2098513
commit
a94ad17abc
@ -10,16 +10,54 @@ namespace MyUserControls.Components
|
|||||||
{
|
{
|
||||||
public partial class testComponent : Component
|
public partial class testComponent : Component
|
||||||
{
|
{
|
||||||
|
private string _fileName;
|
||||||
|
public string FileName
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(value)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!value.EndsWith(".txt"))
|
||||||
|
{
|
||||||
|
throw new ArgumentException("No txt file");
|
||||||
|
}
|
||||||
|
_fileName = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
public testComponent()
|
public testComponent()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_fileName = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public testComponent(IContainer container)
|
public testComponent(IContainer container)
|
||||||
{
|
{
|
||||||
container.Add(this);
|
container.Add(this);
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_fileName = string.Empty;
|
||||||
}
|
}
|
||||||
|
public bool SaveToFile(string[] texts)
|
||||||
|
{
|
||||||
|
CheckFileExsists();
|
||||||
|
using var writer = new StreamWriter(_fileName, true);
|
||||||
|
foreach (var text in texts)
|
||||||
|
{
|
||||||
|
writer.WriteLine(text);
|
||||||
|
}
|
||||||
|
writer.Flush();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
private void CheckFileExsists()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(_fileName))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(_fileName);
|
||||||
|
}
|
||||||
|
if (!File.Exists(_fileName))
|
||||||
|
{
|
||||||
|
throw new FileNotFoundException(_fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace MyUserControls.VisualComponents
|
namespace MyUserControls
|
||||||
{
|
{
|
||||||
public class ValueOutOfRangeException : Exception
|
public class ValueOutOfRangeException : Exception
|
||||||
{
|
{
|
||||||
|
27
WinFormsApp1/Form1.Designer.cs
generated
27
WinFormsApp1/Form1.Designer.cs
generated
@ -28,9 +28,13 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
|
components = new System.ComponentModel.Container();
|
||||||
smartCheckedListBox1 = new MyUserControls.SmartCheckedListBox();
|
smartCheckedListBox1 = new MyUserControls.SmartCheckedListBox();
|
||||||
smartTextBox1 = new MyUserControls.SmartTextBox();
|
smartTextBox1 = new MyUserControls.SmartTextBox();
|
||||||
hierarchicalTreeView = new MyUserControls.HierarchicalTreeView();
|
hierarchicalTreeView = new MyUserControls.HierarchicalTreeView();
|
||||||
|
testComponent1 = new MyUserControls.Components.testComponent(components);
|
||||||
|
buttonSave = new Button();
|
||||||
|
richTextBoxText = new RichTextBox();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// smartCheckedListBox1
|
// smartCheckedListBox1
|
||||||
@ -57,11 +61,31 @@
|
|||||||
hierarchicalTreeView.Size = new Size(266, 174);
|
hierarchicalTreeView.Size = new Size(266, 174);
|
||||||
hierarchicalTreeView.TabIndex = 3;
|
hierarchicalTreeView.TabIndex = 3;
|
||||||
//
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
buttonSave.Location = new Point(337, 162);
|
||||||
|
buttonSave.Name = "buttonSave";
|
||||||
|
buttonSave.Size = new Size(168, 32);
|
||||||
|
buttonSave.TabIndex = 4;
|
||||||
|
buttonSave.Text = "Сохранить";
|
||||||
|
buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
buttonSave.Click += buttonSave_Click;
|
||||||
|
//
|
||||||
|
// richTextBoxText
|
||||||
|
//
|
||||||
|
richTextBoxText.Location = new Point(337, 26);
|
||||||
|
richTextBoxText.Name = "richTextBoxText";
|
||||||
|
richTextBoxText.Size = new Size(168, 130);
|
||||||
|
richTextBoxText.TabIndex = 5;
|
||||||
|
richTextBoxText.Text = "";
|
||||||
|
//
|
||||||
// Form1
|
// Form1
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(1120, 450);
|
ClientSize = new Size(1120, 450);
|
||||||
|
Controls.Add(richTextBoxText);
|
||||||
|
Controls.Add(buttonSave);
|
||||||
Controls.Add(hierarchicalTreeView);
|
Controls.Add(hierarchicalTreeView);
|
||||||
Controls.Add(smartTextBox1);
|
Controls.Add(smartTextBox1);
|
||||||
Controls.Add(smartCheckedListBox1);
|
Controls.Add(smartCheckedListBox1);
|
||||||
@ -75,5 +99,8 @@
|
|||||||
private MyUserControls.SmartCheckedListBox smartCheckedListBox1;
|
private MyUserControls.SmartCheckedListBox smartCheckedListBox1;
|
||||||
private MyUserControls.SmartTextBox smartTextBox1;
|
private MyUserControls.SmartTextBox smartTextBox1;
|
||||||
private MyUserControls.HierarchicalTreeView hierarchicalTreeView;
|
private MyUserControls.HierarchicalTreeView hierarchicalTreeView;
|
||||||
|
private MyUserControls.Components.testComponent testComponent1;
|
||||||
|
private Button buttonSave;
|
||||||
|
private RichTextBox richTextBoxText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using MyUserControls;
|
using MyUserControls;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
namespace WinFormsApp1
|
namespace WinFormsApp1
|
||||||
{
|
{
|
||||||
@ -10,6 +11,7 @@ namespace WinFormsApp1
|
|||||||
InitialChekedListBox();
|
InitialChekedListBox();
|
||||||
InitialSmartTextBox();
|
InitialSmartTextBox();
|
||||||
InitialTree();
|
InitialTree();
|
||||||
|
testComponent1.FileName = "1.txt";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitialChekedListBox()
|
private void InitialChekedListBox()
|
||||||
@ -51,5 +53,22 @@ namespace WinFormsApp1
|
|||||||
|
|
||||||
smartTextBox1.InputText = hierarchicalTreeView.GetSelectedItem<SampleClass>().ToString();
|
smartTextBox1.InputText = hierarchicalTreeView.GetSelectedItem<SampleClass>().ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void buttonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
testComponent1.SaveToFile(richTextBoxText.Lines);
|
||||||
|
MessageBox.Show("Ñîõàðíåíî óñïåøíî", "Ðåçóëüòàò",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Îøèáêà",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,4 +117,7 @@
|
|||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
|
<metadata name="testComponent1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>17, 17</value>
|
||||||
|
</metadata>
|
||||||
</root>
|
</root>
|
39
WinFormsApp1/Form2.Designer.cs
generated
39
WinFormsApp1/Form2.Designer.cs
generated
@ -1,39 +0,0 @@
|
|||||||
namespace WinFormsApp1
|
|
||||||
{
|
|
||||||
partial class Form2
|
|
||||||
{
|
|
||||||
/// <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()
|
|
||||||
{
|
|
||||||
this.components = new System.ComponentModel.Container();
|
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
|
||||||
this.Text = "Form2";
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
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 WinFormsApp1
|
|
||||||
{
|
|
||||||
public partial class Form2 : Form
|
|
||||||
{
|
|
||||||
public Form2()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,120 +0,0 @@
|
|||||||
<?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>
|
|
Loading…
Reference in New Issue
Block a user