тяп ляп готово

This commit is contained in:
Леонид Малафеев 2024-09-06 00:43:56 +04:00
parent b671cbbcad
commit 3939413204
12 changed files with 321 additions and 86 deletions

View File

@ -26,6 +26,7 @@ namespace Controls
public void ComboBoxClear()
{
comboBoxMain.Items.Clear();
comboBoxMain.SelectedItem = null;
}
/// <summary>
@ -37,11 +38,11 @@ namespace Controls
{
if (comboBoxMain.Items.Count == 0)
{
return "";
return " ";
}
if (comboBoxMain.SelectedItem == null)
{
return "";
return " ";
}
return comboBoxMain.SelectedItem.ToString()!;
}

View File

@ -36,9 +36,9 @@
listBoxMain.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
listBoxMain.FormattingEnabled = true;
listBoxMain.ItemHeight = 20;
listBoxMain.Location = new Point(38, 42);
listBoxMain.Location = new Point(3, 3);
listBoxMain.Name = "listBoxMain";
listBoxMain.Size = new Size(197, 104);
listBoxMain.Size = new Size(270, 184);
listBoxMain.TabIndex = 0;
//
// CustomListBox
@ -47,7 +47,7 @@
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(listBoxMain);
Name = "CustomListBox";
Size = new Size(276, 200);
Size = new Size(276, 212);
ResumeLayout(false);
}

View File

@ -29,17 +29,17 @@ namespace Controls
/// <summary>
/// Символ начала
/// </summary>
private char _startSymbol = '{';
private string _startSymbol;
/// <summary>
/// Символ конца
/// </summary>
private char _endSymbol = '}';
private string _endSymbol;
/// <summary>
/// Шаблон строки
/// </summary>
public void SetTemplateString(string templateString, char startSymbol = '{', char endSymbol = '}')
public void SetTemplateString(string templateString, string startSymbol, string endSymbol)
{
_templateString = templateString;
_startSymbol = startSymbol;
@ -70,7 +70,7 @@ namespace Controls
{
return null;
}
string row = listBoxMain.SelectedItem.ToString()!;
string row = listBoxMain.SelectedItem.ToString();
T curObject = new T();
StringBuilder sb = new StringBuilder(row);
foreach (var property in typeof(T).GetProperties())

View File

@ -9,7 +9,6 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace Controls
{
@ -31,7 +30,12 @@ namespace Controls
/// <summary>
/// Шаблон вводимого значения
/// </summary>
private string? NumPattern
private string? _numberExample = "+79991144333";
/// <summary>
/// Шаблон вводимого значения
/// </summary>
public string? NumPattern
{
get { return _numberPattern; }
set { _numberPattern = value; }
@ -101,5 +105,15 @@ namespace Controls
{
_onValueChangedEvent?.Invoke(sender, e);
}
/// <summary>
/// Вывод подсказки с примером правильного ввода
/// </summary>
private void textBox_Enter(object sender, EventArgs e)
{
int visibleTime = 2000;
ToolTip tooltip = new ToolTip();
tooltip.Show(_numberExample, textBoxNumber, 30, -20, visibleTime);
}
}
}

View File

@ -1,39 +0,0 @@
namespace Forms
{
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()
{
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
}
}

View File

@ -1,10 +0,0 @@
namespace Forms
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

175
Cop_25/Forms/FormMain.Designer.cs generated Normal file
View File

@ -0,0 +1,175 @@
namespace Forms
{
partial class FormMain
{
/// <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()
{
components = new System.ComponentModel.Container();
customTextBoxNumber = new Controls.CustomTextBoxNumber();
customComboBox = new Controls.CustomComboBox();
labelNum = new Label();
labelCombo = new Label();
labelList = new Label();
customListBox = new Controls.CustomListBox();
buttonValidate = new Button();
buttonGetBro = new Button();
toolTip = new ToolTip(components);
button1 = new Button();
button2 = new Button();
SuspendLayout();
//
// customTextBoxNumber
//
customTextBoxNumber.Location = new Point(2, 187);
customTextBoxNumber.Name = "customTextBoxNumber";
customTextBoxNumber.NumPattern = null;
customTextBoxNumber.Size = new Size(261, 105);
customTextBoxNumber.TabIndex = 0;
//
// customComboBox
//
customComboBox.Location = new Point(2, 19);
customComboBox.Name = "customComboBox";
customComboBox.SelectedItem = "";
customComboBox.Size = new Size(301, 188);
customComboBox.TabIndex = 1;
//
// labelNum
//
labelNum.AutoSize = true;
labelNum.Location = new Point(68, 187);
labelNum.Name = "labelNum";
labelNum.Size = new Size(130, 20);
labelNum.TabIndex = 2;
labelNum.Text = "Номер телефона:";
//
// labelCombo
//
labelCombo.AutoSize = true;
labelCombo.Location = new Point(88, 42);
labelCombo.Name = "labelCombo";
labelCombo.Size = new Size(95, 20);
labelCombo.TabIndex = 3;
labelCombo.Text = "Комбо бокс:";
//
// labelList
//
labelList.AutoSize = true;
labelList.Location = new Point(509, 19);
labelList.Name = "labelList";
labelList.Size = new Size(59, 20);
labelList.TabIndex = 4;
labelList.Text = "Спсиок";
//
// customListBox
//
customListBox.Location = new Point(334, 42);
customListBox.Name = "customListBox";
customListBox.SelectedIndex = -1;
customListBox.Size = new Size(454, 250);
customListBox.TabIndex = 5;
//
// buttonValidate
//
buttonValidate.Location = new Point(22, 298);
buttonValidate.Name = "buttonValidate";
buttonValidate.Size = new Size(215, 29);
buttonValidate.TabIndex = 6;
buttonValidate.Text = "проверка телефона";
buttonValidate.UseVisualStyleBackColor = true;
buttonValidate.Click += buttonValidate_Click;
//
// buttonGetBro
//
buttonGetBro.Location = new Point(334, 263);
buttonGetBro.Name = "buttonGetBro";
buttonGetBro.Size = new Size(273, 29);
buttonGetBro.TabIndex = 7;
buttonGetBro.Text = "получить альтушку";
buttonGetBro.UseVisualStyleBackColor = true;
buttonGetBro.Click += buttonGetObject_Click;
//
// toolTip
//
toolTip.ToolTipTitle = "AAAA";
//
// button1
//
button1.Location = new Point(22, 119);
button1.Name = "button1";
button1.Size = new Size(94, 29);
button1.TabIndex = 8;
button1.Text = "добавить";
button1.UseVisualStyleBackColor = true;
button1.Click += buttonAdd_Click;
//
// button2
//
button2.Location = new Point(143, 119);
button2.Name = "button2";
button2.Size = new Size(94, 29);
button2.TabIndex = 9;
button2.Text = "очистить";
button2.UseVisualStyleBackColor = true;
button2.Click += buttonClear_Click;
//
// FormMain
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(button2);
Controls.Add(button1);
Controls.Add(buttonGetBro);
Controls.Add(buttonValidate);
Controls.Add(customListBox);
Controls.Add(labelList);
Controls.Add(labelCombo);
Controls.Add(labelNum);
Controls.Add(customComboBox);
Controls.Add(customTextBoxNumber);
Name = "FormMain";
Text = "FormMain";
ResumeLayout(false);
PerformLayout();
}
#endregion
private Controls.CustomTextBoxNumber customTextBoxNumber;
private Controls.CustomComboBox customComboBox;
private Label labelNum;
private Label labelCombo;
private Label labelList;
private Controls.CustomListBox customListBox;
private Button buttonValidate;
private Button buttonGetBro;
private ToolTip toolTip;
private Button button1;
private Button button2;
}
}

72
Cop_25/Forms/FormMain.cs Normal file
View File

@ -0,0 +1,72 @@
using Controls;
using Controls.Exceptions;
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 Forms
{
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
customComboBox.ComboBoxItems.Add("aboba1");
customComboBox.ComboBoxItems.Add("aboba2");
customTextBoxNumber.NumPattern = @"^\+7\d{10}$";
customListBox.SetTemplateString("Имя: {FirstName}, Фамилия: {LastName}, Возраст: {Age}", "{", "}");
Person person1 = new Person { FirstName = "{Лена}", LastName = "{Пряникова}", Age = "{18}" };
Person person2 = new Person { FirstName = "{Ева}", LastName = "{Конфетковна}", Age = "{20}" };
customListBox.FillProperty(person1, 0, "FirstName");
customListBox.FillProperty(person1, 0, "LastName");
customListBox.FillProperty(person1, 0, "Age");
customListBox.FillProperty(person2, 1, "FirstName");
customListBox.FillProperty(person2, 1, "LastName");
customListBox.FillProperty(person2, 1, "Age");
}
private void buttonValidate_Click(object sender, EventArgs e)
{
try
{
string phoneNumber = customTextBoxNumber.TextBoxNumber;
MessageBox.Show($"Введенный номер: {phoneNumber}");
}
catch (CustomNumberException ex)
{
MessageBox.Show($"Ошибка: {ex.Message}");
}
}
private void buttonGetObject_Click(object sender, EventArgs e)
{
try
{
Person selectedPerson = customListBox.GetObjectFromStr<Person>();
MessageBox.Show($"Имя: {selectedPerson.FirstName}, Фамилия: {selectedPerson.LastName}, Возраст: {selectedPerson.Age}");
}
catch (Exception ex)
{
MessageBox.Show($"Ошибка: {ex.Message}");
}
}
private void buttonClear_Click(object sender, EventArgs e) {
customComboBox.ComboBoxClear();
}
private void buttonAdd_Click(object sender, EventArgs e)
{
customComboBox.ComboBoxItems.Add("abobaSECRET");
}
}
}

View File

@ -1,17 +1,17 @@
<?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
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>
@ -26,36 +26,36 @@
<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
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
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
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
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
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
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
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -8,4 +8,8 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Controls\Controls.csproj" />
</ItemGroup>
</Project>

15
Cop_25/Forms/Person.cs Normal file
View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Forms
{
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Age { get; set; }
}
}

View File

@ -11,7 +11,7 @@ namespace Forms
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
Application.Run(new FormMain());
}
}
}