/****************************** * 说明:自定义控件基类 * 创建人:龚宇超 * 创建日期:2017-08-04 * 修改人: * 修改日期: * 修改备注: * 版本:1.0.0.0 ******************************/ using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using Lskj.Control.Model; using Lskj.Business; namespace Lskj.Control { /// /// 基类控件 /// public partial class BaseUserControl : UserControl { /// /// Label填充值 /// protected int PaddingLeft = 7; /// /// 一个字符占用宽度 /// private int CharWidth = 22; private float DefaultFontSize = 12; /// /// 只读颜色 /// protected Color ReadOnlyLabelForceColor = Color.FromArgb(160, 160, 160); /// /// 必填颜色 /// protected Color RequiredLabelForceColor = string.IsNullOrEmpty(SystemInfo.Instance.ControlRequiredColor) ? Color.Blue : ColorTranslator.FromHtml(SystemInfo.Instance.ControlRequiredColor); /// /// Label 默认颜色 /// protected Color DefaultLabelForceColor = Color.Black; /// /// Gets or sets the is empty. /// /// The is empty. public virtual bool IsEmpty() { return this.Model != null && this.Model.IsEmpty && string.IsNullOrWhiteSpace(this.EditText); } /// /// 说明:数据是否修改 /// 创建人:龚宇超 /// 创建日期:2017-11-06 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// true if this instance is update; otherwise, false. public virtual bool IsUpdate() { string UpdContrast = this.EditText; switch (Model.FieldType) { case ControlType.LabDate: case ControlType.LabDateTime: case ControlType.LabDateTimeShort: case ControlType.LabTime: case ControlType.LabShortTime: // 日期控件 LabelDateEdit dateEdit = this as LabelDateEdit; UpdContrast = dateEdit.TextEdit.EditValue == null ? dateEdit.EditText : dateEdit.TextEdit.EditValue.ToString(); break; } return this.Model == null || this.Model.Text == null || !this.Model.Text.Equals(UpdContrast, StringComparison.OrdinalIgnoreCase); } /// /// LebelText /// public virtual string LabelText { get; set; } /// /// Label、TextEdit Size /// /// The size of the control. public virtual float FontSize { get; set; } /// /// 控件值 /// public virtual string EditText { get; set; } /// /// 控件提示信息 /// public virtual string NullText { get; set; } /// /// 只读控件是否可编辑 /// /// The color of the read only label. public virtual bool ReadOnly { get; set; } /// /// 必填文本颜色 /// /// The color of the required label. public virtual bool Required { get; set; } /// /// 控件Model /// public virtual ControlModel Model { get; set; } protected int GetCharWidth() { return Convert.ToInt32(CharWidth + (FontSize > DefaultFontSize ? FontSize - DefaultFontSize : 0)); } /// /// 设置了非中文的语言后,重新计算控件Label外层大小 /// /// /// /// protected void GetCharWidthMultilingual(Label label, string text, Panel panel) { //之前只对非中文模式生效,后发现GetCharWidth()方法计算不准确,就改成通用设置 //Business.Impl.LanguageTranslation.Translatable && if (text.Length > 0) { using (Graphics graphics = label.CreateGraphics()) { // 使用TextRenderer而不是Graphics.MeasureString,以匹配Label的文本渲染方式 Size textSize = TextRenderer.MeasureText(graphics, text, label.Font); panel.Width= textSize.Width; } } } public BaseUserControl() { InitializeComponent(); } public void ModifyDefaultColors(Color color) { DefaultLabelForceColor = color; } } }