You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lj_plc/Controls/Mesnac.Controls.Default/ReplaceLabel.cs

359 lines
9.0 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Mesnac.Controls.Default
{
[ToolboxBitmap(typeof(System.Windows.Forms.Label))]
public partial class ReplaceLabel : System.Windows.Forms.Label
{
public ReplaceLabel()
{
InitializeComponent();
}
public ReplaceLabel(IContainer container)
{
container.Add(this);
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs pe)
{
// TODO: 在此处添加自定义绘制代码
// 调用基类 OnPaint
base.OnPaint(pe);
}
#region bHaveAction
private bool _bHaveAction = false;
public bool bHaveAction
{
get
{
return _bHaveAction;
}
set
{
_bHaveAction = value;
}
}
#endregion
#region Text
private string _replaceExpress = string.Empty;
private Dictionary<string, string> dic = new Dictionary<string, string>();
/// <summary>
/// 替换表达式0:未处理|1:已处理
/// </summary>
public string ReplaceExpress
{
get
{
return _replaceExpress;
}
set
{
_replaceExpress = value;
if (!String.IsNullOrWhiteSpace(this._replaceExpress))
{
string[] replaces = this._replaceExpress.Split(new char[] { '|' });
dic.Clear();
foreach (string str in replaces)
{
string[] ss = str.Split(new char[] { ':' });
if (ss.Length == 2 && !dic.ContainsKey(ss[0]))
{
dic.Add(ss[0], ss[1]);
}
}
}
}
}
private string _textName = null;
public string TextName
{
get
{
return _textName;
}
set
{
_textName = value;
}
}
private string _textValue = string.Empty;
public string TextValue
{
set
{
this._textValue = value;
if (!this.DesignMode)
{
if (string.IsNullOrWhiteSpace(this._replaceExpress))
{
this.Text = this._textValue;
}
else
{
//this.Text = string.Format(this.Format, this._textValue);
if (String.IsNullOrWhiteSpace(this._textValue))
{
this.Text = String.Empty;
}
else
{
this.Text = this.dic.ContainsKey(this._textValue) ? this.dic[this._textValue] : String.Empty;
}
}
}
}
get
{
return this._textValue;
}
}
#endregion
#region Left
private string _xName = null;
public string XName
{
get
{
return _xName;
}
set
{
_xName = value;
}
}
private int? _xValue = null;
public int? XValue
{
set
{
this._xValue = value;
if (!this.DesignMode)
{
if (this._xValue != null)
{
this.Left = (int)this._xValue;
}
}
}
get
{
return this._xValue;
}
}
#endregion
#region Top
private string _yName = null;
public string YName
{
get
{
return _yName;
}
set
{
_yName = value;
}
}
private int? _yValue = null;
public int? YValue
{
set
{
this._yValue = value;
if (!this.DesignMode)
{
if (this._yValue != null)
{
this.Top = (int)this._yValue;
}
}
}
get
{
return this._yValue;
}
}
#endregion
#region Width
private string _widthName = null;
public string WidthName
{
get
{
return _widthName;
}
set
{
_widthName = value;
}
}
private int? _widthValue = null;
public int? WidthValue
{
set
{
this._widthValue = value;
if (!this.DesignMode)
{
if (this._widthValue != null)
{
this.Width = (int)this._widthValue;
}
}
}
get
{
return this._widthValue;
}
}
#endregion
#region Height
private string _heightName = null;
public string HeightName
{
get
{
return _heightName;
}
set
{
_heightName = value;
}
}
private int? _heightValue = null;
public int? HeightValue
{
set
{
this._heightValue = value;
if (!this.DesignMode)
{
if (this._heightValue != null && !this.DesignMode)
{
this.Height = (int)this._heightValue;
}
}
}
get
{
return this._heightValue;
}
}
#endregion
#region Visible
//private string _visibleName = null;
//public string VisibleName
//{
// get
// {
// return _visibleName;
// }
// set
// {
// _visibleName = value;
// }
//}
//private int? _visibleValue = null;
//public int? VisibleValue
//{
// set
// {
// this._visibleValue = value;
// if (!this.DesignMode)
// {
// if (this._visibleValue != null)
// {
// this.Visible = ((int)this._visibleValue > 5);
// this.Refresh();
// }
// }
// }
// get
// {
// return this._visibleValue;
// }
//}
#endregion
#region FillColor
private Color _newFillColor = Color.Red;
[Description("背景色2"), Category("Appearance")]
public Color NewFillColor
{
get
{
return _newFillColor;
}
set
{
_newFillColor = value;
}
}
//原背景色
private Color _oldFillColor = Color.DarkGray;
[Description("背景色1"), Category("Appearance")]
public Color OldFillColor
{
get
{
return _oldFillColor;
}
set
{
_oldFillColor = value;
}
}
private string _fillColorName = null;
public string FillColorName
{
get
{
return _fillColorName;
}
set
{
_fillColorName = value;
}
}
private int? _fillColorValue = null;
public int? FillColorValue
{
set
{
this._fillColorValue = value;
if (!this.DesignMode)
{
if (this._fillColorValue != null)
{
if ((int)this._fillColorValue > 0)
{
this.BackColor = this.NewFillColor;
}
else
{
this.BackColor = this.OldFillColor;
}
}
}
}
get
{
return this._fillColorValue;
}
}
#endregion
}
}