From c8777e45492f03fb6ce3ab11ab4e13be22fdeece Mon Sep 17 00:00:00 2001 From: frog24 Date: Sat, 21 Sep 2024 21:03:55 +0300 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=D1=8B=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=B5=D1=80=D0=B2=D1=8B=D1=85=20=D0=B4=D0=B2?= =?UTF-8?q?=D1=83=D1=85=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=20=D0=B8=20=D0=BD=D0=B0=D1=87=D0=B0=D0=BB?= =?UTF-8?q?=D0=BE=20=D1=81=D1=82=D1=80=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B9?= =?UTF-8?q?=20=D1=81=20=D1=82=D1=80=D0=B5=D1=82=D1=8C=D0=B8=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Components/CustomComboBox.cs | 7 +------ Components/CustomListBox.cs | 12 +++++++++++- Components/CustomTextBox.cs | 4 ++++ CustomComboBox/TestApp/Form1.Designer.cs | 4 ++-- CustomComboBox/TestApp/Form1.cs | 8 ++++---- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Components/CustomComboBox.cs b/Components/CustomComboBox.cs index 644a0c9..068ed65 100644 --- a/Components/CustomComboBox.cs +++ b/Components/CustomComboBox.cs @@ -28,12 +28,7 @@ namespace Components { get { - if (comboBox.Items.Count == 0 || comboBox.SelectedItem == null) - { - return string.Empty; - } - return comboBox.SelectedItem.ToString(); - } + return comboBox.SelectedItem?.ToString() ?? string.Empty; } set { comboBox.SelectedItem = value; diff --git a/Components/CustomListBox.cs b/Components/CustomListBox.cs index 216e055..ffa8ea4 100644 --- a/Components/CustomListBox.cs +++ b/Components/CustomListBox.cs @@ -55,6 +55,15 @@ namespace Components string row = listBox.SelectedItem.ToString(); T curObject = new T(); StringBuilder sb = new StringBuilder(row); + + MessageBox.Show(sb.ToString()); + + //("Дорогой дневник, мне не подобрать слов чтобы описать всю {Mood}, что я испытал сегодня; {Date}", "{", "}"); + // "Дорогой дневник, мне не подобрать слов чтобы описать всю радость пенис, что я испытал сегодня; блаблабла" + StringBuilder tp = new StringBuilder(template); + + + foreach (var property in typeof(T).GetProperties()) { if (!property.CanWrite) @@ -62,6 +71,8 @@ namespace Components continue; } + //MessageBox.Show(property.Name); + int startBorder = sb.ToString().IndexOf(start); if (startBorder == -1) { @@ -83,7 +94,6 @@ namespace Components public void FillProperty(T dataObject, int rowIndex, string propertyName) { - while (listBox.Items.Count <= rowIndex) { listBox.Items.Add(template); diff --git a/Components/CustomTextBox.cs b/Components/CustomTextBox.cs index 0677f47..e9c0602 100644 --- a/Components/CustomTextBox.cs +++ b/Components/CustomTextBox.cs @@ -52,6 +52,10 @@ namespace Components } set { + if (string.IsNullOrEmpty(_numberPattern)) + { + return; + } Regex regex = new(_numberPattern); if (regex.IsMatch(value)) { diff --git a/CustomComboBox/TestApp/Form1.Designer.cs b/CustomComboBox/TestApp/Form1.Designer.cs index 1ad0b1e..986ff11 100644 --- a/CustomComboBox/TestApp/Form1.Designer.cs +++ b/CustomComboBox/TestApp/Form1.Designer.cs @@ -96,7 +96,7 @@ customListBox.Location = new Point(296, 0); customListBox.Name = "customListBox"; customListBox.SelectedRow = -1; - customListBox.Size = new Size(803, 400); + customListBox.Size = new Size(848, 400); customListBox.TabIndex = 5; // // buttonDay @@ -139,7 +139,7 @@ // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1111, 416); + ClientSize = new Size(1156, 416); Controls.Add(label1); Controls.Add(textBoxMood); Controls.Add(buttonAddDay); diff --git a/CustomComboBox/TestApp/Form1.cs b/CustomComboBox/TestApp/Form1.cs index 076ed85..896ef1e 100644 --- a/CustomComboBox/TestApp/Form1.cs +++ b/CustomComboBox/TestApp/Form1.cs @@ -65,10 +65,10 @@ namespace TestApp private void FillCustomListBox() { - Day day1 = new Day() { Mood = "{}", Date = DateTime.Now }; - Day day2 = new Day() { Mood = "{}", Date = DateTime.Now.AddDays(1.0) }; + Day day1 = new Day() { Mood = "", Date = DateTime.Now }; + Day day2 = new Day() { Mood = "", Date = DateTime.Now.AddDays(1.0) }; - customListBox.setTemplate(" , {Mood}, ; {{Date}}", "{", "}"); + customListBox.setTemplate(" , {Mood}, ; {Date}", "{", "}"); customListBox.FillProperty(day1, 0, "Mood"); customListBox.FillProperty(day1, 0, "Date"); @@ -89,7 +89,7 @@ namespace TestApp day.Date = DateTime.Now; if (string.IsNullOrEmpty(textBoxMood.Text)) { - MessageBox.Show("Write something!!!"); + MessageBox.Show("Write something!!!", "Error"); return; } day.Mood = "{" + textBoxMood.Text + "}";