Files
lserp_cs_6.0/插件库/Lskj.Control/LabelDateHalfDayEdit.cs
T
cyf 2b2d109132 SVN r1230
SVN-Revision: r1230
2026-06-23 09:17:23 +00:00

214 lines
6.4 KiB
C#

using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using Lskj.Control.SpecialDate;
namespace Lskj.Control
{
/// <summary>
/// 日期半天控件,显示格式为 yyyy-MM-dd 上午/下午。
/// </summary>
public partial class LabelDateHalfDayEdit : BaseUserControl
{
private SpecialDatePopup specialDatePopup;
private PopupContainerControl popupControl;
/// <summary>
/// 日期半天下拉编辑框。
/// </summary>
public PopupContainerEdit TextEdit { get { return txtEdit; } }
/// <summary>
/// 左侧文本。
/// </summary>
public Label Label { get { return lblText; } }
public LabelDateHalfDayEdit()
{
InitializeComponent();
InitPopup();
}
/// <summary>
/// 设置控件显示文本。
/// </summary>
public override string LabelText
{
get
{
return this.lblText.Text;
}
set
{
this.lblText.Text = value;
if (FontSize > 0)
{
this.plLeft.Dock = DockStyle.Left;
this.plLeft.AutoSize = false;
this.lblText.AutoSize = false;
this.lblText.Dock = DockStyle.Fill;
this.lblText.Location = new Point(0, 0);
this.lblText.TextAlign = ContentAlignment.MiddleLeft;
this.txtEdit.Properties.AutoHeight = false;
this.plLeft.Width = value.Length * GetCharWidth();
GetCharWidthMultilingual(this.lblText, this.lblText.Text, this.plLeft);
}
else
{
this.plLeft.Width = this.lblText.Width + PaddingLeft;
}
}
}
/// <summary>
/// 字体大小。
/// </summary>
public override float FontSize
{
get
{
return base.FontSize;
}
set
{
base.FontSize = value;
if (value > 0)
{
this.lblText.Font = new Font(this.lblText.Font.FontFamily, value);
this.TextEdit.Font = new Font(this.TextEdit.Font.FontFamily, value);
}
}
}
/// <summary>
/// 设置控件值,MyControl.SetControlValue 会通过该属性给控件赋值。
/// </summary>
public override string EditText
{
get
{
return this.txtEdit.Text;
}
set
{
this.txtEdit.EditValue = string.IsNullOrWhiteSpace(value) ? null : value;
}
}
/// <summary>
/// 控件提示文本。
/// </summary>
public override string NullText
{
get
{
return this.txtEdit.Properties.NullValuePrompt;
}
set
{
if (!string.IsNullOrEmpty(value))
{
this.TextEdit.Properties.NullValuePromptShowForEmptyValue = true;
this.TextEdit.Properties.NullValuePrompt = value;
}
base.NullText = value;
}
}
/// <summary>
/// 只读状态。
/// </summary>
public override bool ReadOnly
{
get
{
return base.ReadOnly;
}
set
{
base.ReadOnly = value;
this.txtEdit.Properties.ReadOnly = value;
this.txtEdit.Enabled = !value;
this.lblText.ForeColor = value ? base.ReadOnlyLabelForceColor : Required ? base.RequiredLabelForceColor : base.DefaultLabelForceColor;
}
}
/// <summary>
/// 必填状态。
/// </summary>
public override bool Required
{
get
{
return base.Required;
}
set
{
base.Required = value;
if (value)
{
this.lblText.ForeColor = base.RequiredLabelForceColor;
}
}
}
private void InitPopup()
{
this.specialDatePopup = new SpecialDatePopup();
this.specialDatePopup.Dock = DockStyle.Fill;
this.popupControl = new PopupContainerControl();
this.popupControl.Controls.Add(this.specialDatePopup);
this.popupControl.Size = this.specialDatePopup.Size;
this.txtEdit.Properties.PopupControl = this.popupControl;
this.txtEdit.Properties.TextEditStyle = TextEditStyles.Standard;
this.txtEdit.QueryPopUp += TextEdit_QueryPopUp;
this.specialDatePopup.ConfirmClick += SpecialDatePopup_ConfirmClick;
this.specialDatePopup.ClearClick += SpecialDatePopup_ClearClick;
this.specialDatePopup.CancelClick += SpecialDatePopup_CancelClick;
}
private void TextEdit_QueryPopUp(object sender, CancelEventArgs e)
{
this.popupControl.Size = this.specialDatePopup.Size;
this.specialDatePopup.OwnerEdit = this.txtEdit;
this.specialDatePopup.SetValue(this.txtEdit.EditValue + "");
}
private void SpecialDatePopup_ConfirmClick(object sender, System.EventArgs e)
{
this.txtEdit.EditValue = this.specialDatePopup.SelectedValue;
this.txtEdit.ClosePopup();
}
private void SpecialDatePopup_ClearClick(object sender, System.EventArgs e)
{
this.txtEdit.EditValue = string.Empty;
this.txtEdit.ClosePopup();
}
private void SpecialDatePopup_CancelClick(object sender, System.EventArgs e)
{
this.txtEdit.ClosePopup();
}
/// <summary>
/// 背景颜色
/// </summary>
/// <value>The color of the required label.</value>
public override Color BackgroundColor
{
get
{
return TextEdit.Properties.Appearance.BackColor;
}
set
{
TextEdit.Properties.Appearance.BackColor = value;
}