基线 SVN r240
SVN-Revision: r240
This commit is contained in:
@@ -0,0 +1,158 @@
|
||||
/******************************
|
||||
* 说明:自定义控件基类
|
||||
* 创建人:龚宇超
|
||||
* 创建日期: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
|
||||
{
|
||||
/// <summary>
|
||||
/// 基类控件
|
||||
/// </summary>
|
||||
public partial class BaseUserControl : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Label填充值
|
||||
/// </summary>
|
||||
protected int PaddingLeft = 7;
|
||||
/// <summary>
|
||||
/// 一个字符占用宽度
|
||||
/// </summary>
|
||||
private int CharWidth = 22;
|
||||
private float DefaultFontSize = 12;
|
||||
/// <summary>
|
||||
/// 只读颜色
|
||||
/// </summary>
|
||||
protected Color ReadOnlyLabelForceColor = Color.FromArgb(160, 160, 160);
|
||||
/// <summary>
|
||||
/// 必填颜色
|
||||
/// </summary>
|
||||
protected Color RequiredLabelForceColor = string.IsNullOrEmpty(SystemInfo.Instance.ControlRequiredColor) ? Color.Blue : ColorTranslator.FromHtml(SystemInfo.Instance.ControlRequiredColor);
|
||||
/// <summary>
|
||||
/// Label 默认颜色
|
||||
/// </summary>
|
||||
protected Color DefaultLabelForceColor = Color.Black;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the is empty.
|
||||
/// </summary>
|
||||
/// <value>The is empty.</value>
|
||||
public virtual bool IsEmpty()
|
||||
{
|
||||
return this.Model != null && this.Model.IsEmpty && string.IsNullOrWhiteSpace(this.EditText);
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:数据是否修改</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-11-06 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if this instance is update; otherwise, <c>false</c>.</returns>
|
||||
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);
|
||||
}
|
||||
/// <summary>
|
||||
/// LebelText
|
||||
/// </summary>
|
||||
public virtual string LabelText { get; set; }
|
||||
/// <summary>
|
||||
/// Label、TextEdit Size
|
||||
/// </summary>
|
||||
/// <value>The size of the control.</value>
|
||||
public virtual float FontSize { get; set; }
|
||||
/// <summary>
|
||||
/// 控件值
|
||||
/// </summary>
|
||||
public virtual string EditText { get; set; }
|
||||
/// <summary>
|
||||
/// 控件提示信息
|
||||
/// </summary>
|
||||
public virtual string NullText { get; set; }
|
||||
/// <summary>
|
||||
/// 只读控件是否可编辑
|
||||
/// </summary>
|
||||
/// <value>The color of the read only label.</value>
|
||||
public virtual bool ReadOnly { get; set; }
|
||||
/// <summary>
|
||||
/// 必填文本颜色
|
||||
/// </summary>
|
||||
/// <value>The color of the required label.</value>
|
||||
public virtual bool Required { get; set; }
|
||||
/// <summary>
|
||||
/// 控件Model
|
||||
/// </summary>
|
||||
public virtual ControlModel Model { get; set; }
|
||||
|
||||
|
||||
protected int GetCharWidth()
|
||||
{
|
||||
return Convert.ToInt32(CharWidth + (FontSize > DefaultFontSize ? FontSize - DefaultFontSize : 0));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 设置了非中文的语言后,重新计算控件Label外层大小
|
||||
/// </summary>
|
||||
/// <param name="label"></param>
|
||||
/// <param name="text"></param>
|
||||
/// <param name="panel"></param>
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user