From 82f6fc6e496484d0b18aa565c8cbdea78fad635f Mon Sep 17 00:00:00 2001 From: aleyckin Date: Thu, 21 Sep 2023 10:49:09 +0400 Subject: [PATCH] 2oe dodelal vrode --- .../WinFormsLibrary/NumberTextBox.Designer.cs | 28 ++++++--- .../WinFormsLibrary/NumberTextBox.cs | 59 +++++++++++++++++++ 2 files changed, 80 insertions(+), 7 deletions(-) diff --git a/WinFormsProject/WinFormsLibrary/NumberTextBox.Designer.cs b/WinFormsProject/WinFormsLibrary/NumberTextBox.Designer.cs index 9796547..e31f55d 100644 --- a/WinFormsProject/WinFormsLibrary/NumberTextBox.Designer.cs +++ b/WinFormsProject/WinFormsLibrary/NumberTextBox.Designer.cs @@ -28,18 +28,32 @@ /// private void InitializeComponent() { - this.SuspendLayout(); + numericUpDown = new NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)numericUpDown).BeginInit(); + SuspendLayout(); + // + // numericUpDown + // + numericUpDown.Location = new Point(117, 37); + numericUpDown.Maximum = new decimal(new int[] { 110, 0, 0, 0 }); + numericUpDown.Minimum = new decimal(new int[] { 50, 0, 0, int.MinValue }); + numericUpDown.Name = "numericUpDown"; + numericUpDown.Size = new Size(120, 23); + numericUpDown.TabIndex = 0; // // NumberTextBox // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Name = "NumberTextBox"; - this.Size = new System.Drawing.Size(364, 264); - this.ResumeLayout(false); - + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(numericUpDown); + Name = "NumberTextBox"; + Size = new Size(364, 106); + ((System.ComponentModel.ISupportInitialize)numericUpDown).EndInit(); + ResumeLayout(false); } #endregion + + private NumericUpDown numericUpDown; } } diff --git a/WinFormsProject/WinFormsLibrary/NumberTextBox.cs b/WinFormsProject/WinFormsLibrary/NumberTextBox.cs index 05b2902..58eb6a8 100644 --- a/WinFormsProject/WinFormsLibrary/NumberTextBox.cs +++ b/WinFormsProject/WinFormsLibrary/NumberTextBox.cs @@ -12,9 +12,68 @@ namespace WinFormsLibrary { public partial class NumberTextBox : UserControl { + public int maxValue; + public int minValue; + public bool error = false; + public NumberTextBox() { InitializeComponent(); + + } + + + //публичное свойство + public string Selected + { + get + { + if (minValue == null) + { + error = true; + } + + if (maxValue == null) + { + error = true; + } + + if (Check_Value(Convert.ToInt32(numericUpDown.Value))) + { + return ""; + } + return numericUpDown.Value.ToString(); + } + set + { + if (!Check_Value(Convert.ToInt32(numericUpDown.Value))) + { + error = true; + } + numericUpDown.Value = 0; + } + } + + public void SetMaxValue(int number) // переделать через свойство + { + numericUpDown.Maximum = number; + maxValue = number; + } + + public void SetMinValue(int number) // переделать через свойство + { + numericUpDown.Minimum = number; + minValue = number; + } + + public bool Check_Value(int number) + { + if (number < numericUpDown.Minimum || number > numericUpDown.Maximum) + { + return false; + } + + return true; } } }