DepartmentProject/DepartmentPortal/Common/DesktopTools/BaseControls/BaseControlText.cs

46 lines
1.2 KiB
C#

using ModuleTools.Extensions;
using System;
using System.Drawing;
namespace DesktopTools.BaseControls
{
public partial class BaseControlText : AbstractBaseControl
{
public BaseControlText(string propertyName) : base(propertyName)
{
InitializeComponent();
panelControl.Controls.Add(textBox);
textBox.TextChanged += (object sender, EventArgs e) => { CallOnValueChangeEvent(); };
_originalValue = string.Empty;
}
public override void SetReadOnly(bool readOnly) => textBox.Enabled = !readOnly;
public override void SetValueToControl(object value)
{
base.SetValueToControl(value);
textBox.Text = value.ToString();
}
public override void DropValue() => textBox.Text = _originalValue.ToString();
public override bool CheckValue()
{
if(_mustCheckValue && textBox.Text.IsEmpty())
{
BackColor = Color.OrangeRed;
return false;
}
return true;
}
protected override object GetValueFromControl()
{
if (_mustCheckValue && textBox.Text.IsEmpty())
{
throw new ArgumentNullException($"Поле свойства '{labelTitle.Text}' должно быть заполнено");
}
return textBox.Text;
}
}
}