85 lines
2.4 KiB
C#
85 lines
2.4 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Runtime.CompilerServices;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
|
||
namespace VisableComponents
|
||
{
|
||
public partial class MyTextBoxDate : UserControl
|
||
{
|
||
private EventHandler onValueChanged;
|
||
public event EventHandler ValueChanged
|
||
{
|
||
add
|
||
{
|
||
onValueChanged += value;
|
||
}
|
||
remove
|
||
{
|
||
onValueChanged -= value;
|
||
}
|
||
}
|
||
public string TextEr;
|
||
public string Err { get { return TextEr; } private set { TextEr = value; } }
|
||
public DateTime? DateMin = null;
|
||
public DateTime? DateMax = null;
|
||
public MyTextBoxDate()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
public DateTime? DateMaximum {
|
||
get { return DateMax ; }
|
||
set {
|
||
|
||
DateMax = value;
|
||
|
||
}
|
||
}
|
||
public DateTime? DateMinimum
|
||
{
|
||
get { return DateMin; }
|
||
set
|
||
{
|
||
|
||
DateMin = value;
|
||
|
||
|
||
}
|
||
}
|
||
public DateTime? Value
|
||
{
|
||
get
|
||
{
|
||
if(DateMin is null || DateMax is null) {
|
||
Err = "Ошибка: НЕТ диапазона";
|
||
return null;
|
||
}
|
||
if (dateTimePicker.Value > DateMax || dateTimePicker.Value < DateMin)
|
||
{
|
||
Err = "Ошибка: Выход за допустимые пределы!!!";
|
||
return null;
|
||
}
|
||
return dateTimePicker.Value;
|
||
}
|
||
set
|
||
{
|
||
if (value == null) return;
|
||
if (value > DateMax || value < DateMin) return;
|
||
dateTimePicker.Value = (DateTime)value;
|
||
}
|
||
}
|
||
|
||
private void dateTimePicker_ValueChanged(object sender, EventArgs e)
|
||
{
|
||
if (dateTimePicker.Value >= DateMinimum && dateTimePicker.Value <= DateMaximum) panel.BackColor = Color.LightBlue;
|
||
else panel.BackColor = Color.Red;
|
||
onValueChanged?.Invoke(this,e);
|
||
}
|
||
}
|
||
}
|