关于软元件开发说明

开发步骤如下

1 新建一个类项目引用接口库DeviceInterface.dll

2在项目属性中的生成选项卡中勾先允许不安全代码

3在类中继承DeviceInterface.ElementIProtocol并实现这个接口

例子

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DeviceInterface;
namespace ConfigurateText
{
#region 结构体
[Serializable]//允许序列化
public struct PropertyParameter
{
/// <summary>
/// 元件名
/// </summary>
public string ElementName;
/// <summary>
/// 自动大小
/// </summary>
public bool AutoSize;
/// <summary>
/// 格式化字符串长度
/// </summary>
public string FSL;
/// <summary>
/// 格式字符
/// </summary>
public string FormatString;
/// <summary>
/// 是否接受输入操作
/// </summary>
public bool ReadOnly;
/// <summary>
/// 图版路径
/// </summary>
public string DataImage;
/// <summary>
/// 背景色
/// </summary>
public Color BGColor;
/// <summary>
/// 字体色
/// </summary>
public Color fontColor;
/// <summary>
/// 数据单位
/// </summary>
public string StrUnit;
/// <summary>
/// 脚本字符串
/// </summary>
public string ScriptString;
/// <summary>
/// 数据关联
/// </summary>
public bool DChecked;
/// <summary>
/// 服务器ID
/// </summary>
public int SID;
/// <summary>
/// 变量名
/// </summary>
public string VariableName;
/// <summary>
/// 控件位置与大小
/// </summary>
public Rectangle Rectangle;
/// <summary>
/// 最大值
/// </summary>
public float Max;
/// <summary>
/// 最小值
/// </summary>
public float min;
/// <summary>
/// 级别
/// </summary>
public int Grade;
/// <summary>
/// 锁定
/// </summary>
public bool Lock;
/// <summary>
/// 报警类型
/// </summary>
public AlertsType alerTstype;
/// <summary>
/// 报警值
/// </summary>
public float AlertsData;
/// <summary>
/// 间接
/// </summary>
public bool indirect;
/// <summary>
/// 置顶层
/// </summary>
public bool Front;
/// <summary>
/// 置底层
/// </summary>
public bool Back;
/// <summary>
/// 项目路径
/// </summary>
public string projectPath;
}
/// <summary>
/// 报警类型
/// </summary>
public enum AlertsType : int
{
/// <summary>
/// 不报警
/// </summary>
ATnull = 0,
/// <summary>
/// 大于
/// </summary>
ATGt = 1,
/// <summary>
/// 小于
/// </summary>
ATLt = 2,
/// <summary>
/// 等于
/// </summary>
ATEt = 3
}
#endregion
/*/--------引用
* DeviceInterface
* System.Windows.Forms
* System.Drawing
* 项目属性勾选允许不安全代码
*/
public unsafe partial class ElementClass : UserControl, DeviceInterface.ElementIProtocol
{
#region 接口函数

//项目路径
public string projectPath
{
get
{
return this.my_pp.projectPath;
}
set
{
this.my_pp.projectPath = value;
}
}

//获取参数
public object GetElementParameter
{
get
{
return this.my_pp;
}
set
{
this.my_pp = (PropertyParameter)value;
}
}

//设置目标父容器
public System.Windows.Forms.Control GetControlParent
{
get
{
return this.ControlParent;
}
set
{
this.ControlParent = value;
}
}

//获取类名

public string GetClassName
{
get
{
return "ConfigurateText";
}
}

//锁定位置

 

public bool Lock
{ get
{
return this.my_pp.Lock;
}
set
{
this.my_pp.Lock = value;
}
}

//获取元件坐标
public System.Drawing.Rectangle getLocation
{
get
{
Rectangle rectangle = new Rectangle(this.Location, this.Size);
return rectangle;
}
set
{
Rectangle rectangle = value;
this.Location = rectangle.Location;

this.Size = rectangle.Size;
}
}

//
public object getTag
{
get
{
return this.Tag;
}
set
{
this.Tag = value; ;
}
}

//元件显示名
public string ElementName
{
get
{
return "文本输入框";
}
set
{
if (my_pp.ElementName == null | my_pp.ElementName == "")
{
my_pp.ElementName = value;

}
this.Name = my_pp.ElementName;
}
}

//是否接受子控件

public new bool HasChildren
{
get
{
return false;
}
}

//类图标

public System.Drawing.Image GetIco
{
get
{
return null;
}
}

//边框样式

public System.Windows.Forms.BorderStyle setBorderStyle
{
get
{
return this.BorderStyle;
}
set
{
this.BorderStyle = value;
}
}

//获得新的类

public object GetNewElement(object Ptype)
{
if (Ptype == null) Ptype = new PropertyParameter();
ElementClass elementClass = new ElementClass((PropertyParameter)Ptype);
return elementClass;
}

//运行模式初始化

public unsafe void initialize(bool* mode, DeviceManagers ADSDataGather, object pParameter, dExecuteScript dES)
{
my_pp =(PropertyParameter) pParameter;
this.Font = new Font("宋体", 10, FontStyle.Regular);
this.dEScript = dES;
SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);
EditOrRun = true; ;//设定模式
INMask = mode;

er = my_pp.ReadOnly;

//运行模式时
this.Size = my_pp.Rectangle.Size;//
this.Location = my_pp.Rectangle.Location;
this.BackColor = my_pp.BGColor;
this.er = my_pp.ReadOnly;
if (my_pp.DataImage != null & my_pp.DataImage != "")
{
try
{
this.Image = DeviceInterface.ProjectResources.projectResources.myRespircescs.GetImage(my_pp.DataImage);
}
catch (Exception)
{
this.Image = (Image)Properties.Resources.ResourceManager.GetObject("TextBox");

//throw;
}
}
if (ADSDataGather != null)
{
DG = ADSDataGather;//设定数据源


if (my_pp.VariableName != null & my_pp.VariableName != "")
{
try
{
DT = DG[my_pp.SID][my_pp.VariableName].dataType;
//添加数据邦定
//if (EditOrRun) this.DataBindings.Add("text", DG[my_pp.VariableName], "DataValue");
if (EditOrRun)
{
if (my_pp.indirect)
{
this.DataBindings.Add("indirectDdata", DG[my_pp.SID][my_pp.VariableName], "DataValue");
string DataName = ((dataSource)DG[my_pp.SID][my_pp.VariableName]).DataValue.ToString();
dataSource DS = DG[my_pp.SID][DataName];
if (DS != null)
{
if (DS != null)
{
DataSourceBinding = new Binding("Text", DS, "DataValue");
this.DataBindings.Add(DataSourceBinding);
}
indirectTemName = DataName;
}
}
else
{
if (my_pp.FormatString != "Null")
{
this.DataBindings.Add("text", DG[my_pp.SID][my_pp.VariableName], "DataValue", true, DataSourceUpdateMode.OnPropertyChanged, 10, my_pp.FormatString + my_pp.FSL);
}
else
{
this.DataBindings.Add("text", DG[my_pp.SID][my_pp.VariableName], "DataValue");
}
}

}
}
catch (Exception)
{
DeviceInterface.ProjectResources.projectResources.logHelper.WriteLine("MyText类" + my_pp.SID + ":" + my_pp.VariableName + "变量关联错误");
//MessageBox.Show("MyText类"+my_pp.SID +":"+ my_pp.VariableName + "变量关联错误");
}
}
this.Click += MyText_Click;
this.MouseClick += MyText_MouseClick;
}
}

//向目标容器加入新元件

public void ListViewTrash_ConfigurateLabelClick(object sender, EventArgs e)
{
ElementClass elementClass = new ElementClass(this.my_pp);
if (this.ControlParent != null)
{
this.ControlParent.Controls.Add(elementClass);
}
}
#endregion

以下是类实体代码

#region 变量
/// <summary>
/// 父容器
/// </summary>
Control ControlParent;

 

private PropertyParameter my_pp;
public bool* INMask;
/// <summary>
/// 间接变量名
/// </summary>
private string indirectTemName;
/// <summary>
/// 动态数据源邦定
/// </summary>
private Binding DataSourceBinding;
/// <summary>
/// 脚本处理函数
/// </summary>
dExecuteScript dEScript;
/// <summary>
/// 用户输入操作
/// </summary>
public bool UserInputMotion;
/// <summary>
/// 无焦点
/// </summary>
bool er;
/// <summary>
/// 数据来源
/// </summary>
private DeviceManagers DG;
/// <summary>
/// 数据类型
/// </summary>
private DataType DT;
string text = "";
/// <summary>
/// 是否在编辑模式
/// </summary>
public bool EditOrRun;
/// <summary>
/// 图像
/// </summary>
private Image Image;
private Point mouse_offset;
private bool DragState;
/// <summary>
/// 数据值
/// </summary>
private object PrivDataValue;

#endregion
public PropertyParameter getPP
{
get
{
return my_pp;
}
set
{
my_pp = value;
}
}
[Browsable(true), Category("Appearance")]
public bool geter
{
get
{
return er;
}
set
{
er = value;

}
}
/// <summary>
/// 间接变量关联
/// </summary>
public string indirectDdata
{
get
{
return indirectTemName;
}
set
{
if (indirectTemName != value)
{
if (DataSourceBinding != null)
this.DataBindings.Remove(DataSourceBinding);
dataSource ds = DG[my_pp.SID][value];
if (ds != null)
{
DataSourceBinding = new Binding("Text", ds, "DataValue");
this.DataBindings.Add(DataSourceBinding);
}
indirectTemName = value;
}
}
}
public override string Text
{
get
{
return this.text;

}
set
{
try
{
if (value == null) return;
if (DG != null)
{
DataType DT = ((dataSource)DG[my_pp.SID][my_pp.VariableName]).dataType;
switch (DT)
{
case DataType.nullType:
break;
case DataType.IntegralType:
this.text = value;

float intdata = float.Parse(value);
switch (my_pp.alerTstype)
{
case AlertsType.ATnull:
break;
case AlertsType.ATGt:

if (intdata > my_pp.AlertsData)
{
this.BackColor = Color.Red;
}
else
{
this.BackColor = my_pp.BGColor;
}
break;
case AlertsType.ATLt:

if (intdata < my_pp.AlertsData)
{
this.BackColor = Color.Red;
}
else
{
this.BackColor = my_pp.BGColor;
}
break;
case AlertsType.ATEt:
if (intdata == my_pp.AlertsData)
{
this.BackColor = Color.Red;
}
else
{
this.BackColor = my_pp.BGColor;
}
break;
default:
break;
}
break;
case DataType.DintType:
this.text = value;
Int32 Lintdata = Int32.Parse(value);
switch (my_pp.alerTstype)
{
case AlertsType.ATnull:
break;
case AlertsType.ATGt:

if (Lintdata > my_pp.AlertsData)
{
this.BackColor = Color.Red;
}
else
{
this.BackColor = my_pp.BGColor;
}
break;
case AlertsType.ATLt:

if (Lintdata < my_pp.AlertsData)
{
this.BackColor = Color.Red;
}
else
{
this.BackColor = my_pp.BGColor;
}
break;
case AlertsType.ATEt:
if (Lintdata == my_pp.AlertsData)
{
this.BackColor = Color.Red;
}
else
{
this.BackColor = my_pp.BGColor;
}
break;
default:
break;
}
break;
case DataType.FloatType:
this.text = value;
float Fdata = float.Parse(value);
switch (my_pp.alerTstype)
{
case AlertsType.ATnull:
break;
case AlertsType.ATGt:

if (Fdata > my_pp.AlertsData)
{
this.BackColor = Color.Red;
}
else
{
this.BackColor = my_pp.BGColor;
}
break;
case AlertsType.ATLt:

if (Fdata < my_pp.AlertsData)
{
this.BackColor = Color.Red;
}
else
{
this.BackColor = my_pp.BGColor;
}
break;
case AlertsType.ATEt:
if (Fdata == my_pp.AlertsData)
{
this.BackColor = Color.Red;
}
else
{
this.BackColor = my_pp.BGColor;
}
break;
default:
break;
}
break;
case DataType.BitType:
if (bool.Parse(value))
{
this.text = "true";
}
else
{
this.text = "false";
}
break;
case DataType.LintType:
this.text = value;
UInt32 UInt32data = UInt32.Parse(value);
switch (my_pp.alerTstype)
{
case AlertsType.ATnull:
break;
case AlertsType.ATGt:

if (UInt32data > my_pp.AlertsData)
{
this.BackColor = Color.Red;
}
else
{
this.BackColor = my_pp.BGColor;
}
break;
case AlertsType.ATLt:

if (UInt32data < my_pp.AlertsData)
{
this.BackColor = Color.Red;
}
else
{
this.BackColor = my_pp.BGColor;
}
break;
case AlertsType.ATEt:
if (UInt32data == my_pp.AlertsData)
{
this.BackColor = Color.Red;
}
else
{
this.BackColor = my_pp.BGColor;
}
break;
default:
break;
}
break;
case DataType.Uint16:
this.text = value;
UInt16 UInt16data = UInt16.Parse(value);
switch (my_pp.alerTstype)
{
case AlertsType.ATnull:
break;
case AlertsType.ATGt:

if (UInt16data > my_pp.AlertsData)
{
this.BackColor = Color.Red;
}
else
{
this.BackColor = my_pp.BGColor;
}
break;
case AlertsType.ATLt:

if (UInt16data < my_pp.AlertsData)
{
this.BackColor = Color.Red;
}
else
{
this.BackColor = my_pp.BGColor;
}
break;
case AlertsType.ATEt:
if (UInt16data == my_pp.AlertsData)
{
this.BackColor = Color.Red;
}
else
{
this.BackColor = my_pp.BGColor;
}
break;
default:
break;
}
break;
case DataType.WBType:
break;
case DataType.Time:
UInt32 hh, mm, ss;
UInt32 ud32 = UInt32.Parse(value);
hh = ud32 / 3600000;
ud32 = ud32 - hh * 3600000;
mm = ud32 / 60000;
ud32 = ud32 - mm * 60000;
ss = ud32 / 1000;
this.text = hh.ToString() + ":" + mm.ToString() + ":" + ss.ToString();
break;
case DataType.Double:
this.text = value;
Double Ddata = Double.Parse(value);
switch (my_pp.alerTstype)
{
case AlertsType.ATnull:
break;
case AlertsType.ATGt:

if (Ddata > my_pp.AlertsData)
{
this.BackColor = Color.Red;
}
else
{
this.BackColor = my_pp.BGColor;
}
break;
case AlertsType.ATLt:

if (Ddata < my_pp.AlertsData)
{
this.BackColor = Color.Red;
}
else
{
this.BackColor = my_pp.BGColor;
}
break;
case AlertsType.ATEt:
if (Ddata == my_pp.AlertsData)
{
this.BackColor = Color.Red;
}
else
{
this.BackColor = my_pp.BGColor;
}
break;
default:
break;
}
break;
case DataType.StringData:
this.text = value.ToString();
break;

default:
this.text = value;
break;
}
}
else
{
this.text = value;
}


this.Invalidate();
}
catch (Exception ex)
{

MessageBox.Show(this.my_pp.VariableName + "详细说明:" + ex.Message);
}
}

}
public ElementClass()
{
initialize(new PropertyParameter());
}
public ElementClass(PropertyParameter pParameter)
{
initialize(pParameter);
}
public void initialize(PropertyParameter pParameter)
{
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.Selectable, true);

my_pp = pParameter;
this.Location = my_pp.Rectangle.Location;
this.BackColor = my_pp.BGColor;
this.my_pp.fontColor = Color.Black;

if (my_pp.Rectangle.Width >= 30 & my_pp.Rectangle.Width >= 20)
{
this.Size = my_pp.Rectangle.Size;//


}
else
{
this.Size = new Size(80, 23);
}

if (my_pp.DataImage != null & my_pp.DataImage != "")
{
try
{
this.Image =DeviceInterface.ProjectResources.projectResources.myRespircescs.GetImage(my_pp.DataImage);
}
catch (Exception)
{
this.Image = (Image)Properties.Resources.ResourceManager.GetObject("TextBox");

//throw;
}
}
else
{
this.Image = (Image)Properties.Resources.ResourceManager.GetObject("TextBox");
}


// Font = new Font("Arial", (int)((float)this.Height * 0.15));
this.Text = "123";
this.Click += MyText_Click;
this.MouseClick += MyText_MouseClick;
this.DoubleClick += MyText_DoubleClick;
this.MouseMove += MyText_MouseMove;
this.MouseDown += MyText_MouseDown;
this.MouseUp += MyText_MouseUp;
this.SizeChanged += MyText_SizeChanged;
this.LocationChanged += MyText_LocationChanged;
SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);
}

private void MyText_LocationChanged(object sender, EventArgs e)
{
my_pp.Rectangle.Location = this.Location;
}

/// <summary>
/// 构造函数运行模式
/// </summary>
/// <param name="ADSDataGather"></param>
/// <param name="pParameter"></param>
public ElementClass(bool* mode, dataGather ADSDataGather, PropertyParameter pParameter, dExecuteScript dES)
{

}
/// <summary>
/// 界面操作
/// </summary>
public object JMDataVale
{
get
{
return PrivDataValue;
}
set
{//当在运行模式时,并且数据源不为空时,写入PLC
try
{


DataType DT = ((dataSource)DG[my_pp.SID][my_pp.VariableName]).dataType;
switch (DT)
{
case DataType.nullType:
break;
case DataType.IntegralType:
this.PrivDataValue = Int16.Parse(value.ToString());
break;
case DataType.LintType:
this.PrivDataValue = int.Parse(value.ToString());
break;
case DataType.FloatType:
this.PrivDataValue = float.Parse(value.ToString());
break;
case DataType.BitType:
this.PrivDataValue = float.Parse(value.ToString()) > 0 ? true : false;
break;
case DataType.Uint16:
this.PrivDataValue = UInt16.Parse(value.ToString());
break;
case DataType.WBType:
return;
break;

case DataType.Time:
this.PrivDataValue = value.ToString();

break;
case DataType.DintType:
this.PrivDataValue = int.Parse(value.ToString());
break;
case DataType.Double:
this.PrivDataValue = double.Parse(value.ToString());
break;
case DataType.StringData:
this.PrivDataValue = value.ToString();
break;
default:

break;
}
if (DG != null & EditOrRun & UserInputMotion)
{
if (my_pp.indirect)
{
string dataName = ((dataSource)DG[my_pp.SID][my_pp.VariableName]).DataValue.ToString();
((dataSource)DG[my_pp.SID][dataName]).DataValue = this.PrivDataValue;
}
else
{
((dataSource)DG[my_pp.SID][my_pp.VariableName]).DataValue = this.PrivDataValue;
}

}
this.text = value.ToString();
if (UserInputMotion)
{
UserInputMotion = false;
}
}
catch (Exception e)
{

MessageBox.Show(e.Message);
}
}

}
private void MyText_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right & !EditOrRun)
{
if (MessageBox.Show("您确定要移除些控件吗", "警告", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
this.Parent.Controls.Remove(this);
this.Dispose();
}

}
else if (e.Button == MouseButtons.Left & !EditOrRun)
{


if (DeviceInterface.ProjectResources.projectResources.keyState.ctrl)
{
this.BorderStyle = BorderStyle.FixedSingle;
DeviceInterface.ProjectResources .ChildE = true;
DeviceInterface.ProjectResources.AL.Add(this);
}

}
else if (er & EditOrRun)
{
if (*INMask)
{

if (DeviceInterface.ProjectResources .PUserName.UserGrade < my_pp.Grade)
{
if (!DeviceInterface.ProjectResources.projectResources. UserVerify(my_pp.Grade)) return;
}
//DataIntput Dint = new DataIntput(text, new Rectangle(PointToScreen(this.Location), this.Size));
//DataIntput Dint = new DataIntput(text, new Rectangle(this.Location, this.Size));
//Dint.Parent=(Form)((MyText)sender).Parent;
// Dint.ShowDialog();
// text = Dint.TB.Text;
if (my_pp.indirect)
{
//从接口获取键盘窗口类
frmKeyboard frmkey = DeviceInterface.ProjectResources .projectResources.GetFrmKeyboard();

string DataName = ((dataSource)DG[my_pp.SID][my_pp.VariableName]).DataValue.ToString();
dataSource DS = (dataSource)DG[my_pp.SID][DataName];
if (DS != null)
{
DataType DT = ((dataSource)DG[my_pp.SID][DataName]).dataType;
TextBox Tb = new TextBox();
Tb.Text = text;
if (frmkey.Initialize(ref Tb, ref DataName, my_pp.Max, my_pp.min, DT == DataType.Time ? 1 : 0))
UserInputMotion = true;
this.JMDataVale = Tb.Text;
frmkey.Dispose();
Tb.Dispose();
}

}
else
{


frmKeyboard frmkey = DeviceInterface.ProjectResources.projectResources.GetFrmKeyboard();
DataType DT = ((dataSource)DG[my_pp.SID][my_pp.VariableName]).dataType;
TextBox Tb = new TextBox();
Tb.Text = text;
if (frmkey.Initialize(ref Tb, ref my_pp.VariableName, my_pp.Max, my_pp.min, DT == DataType.Time ? 1 : 0))
UserInputMotion = true;
this.JMDataVale = Tb.Text;
frmkey.Dispose();
Tb.Dispose();
}
this.Invalidate();
if (my_pp.ScriptString != null & my_pp.ScriptString != "")//如果脚本不为空执行脚本
{
// string mystring;
try
{
/*var engine = Python.CreateEngine();
var scope = engine.CreateScope();
scope.SetVariable("Ipy_this", this);//将this Set 到Ipy脚本的Ipy_this值中
//var code = engine.CreateScriptSourceFromFile("my.py");//执行my.py
// mystring = "Ipy_this.mysxl = 1";
var code = engine.CreateScriptSourceFromString(my_pp.ScriptString);
code.Execute(scope);*/
if (dEScript != null) dEScript(my_pp.ScriptString, this);
}
catch (Exception)
{
//脚本执行错误处理
//throw;
}
}
}
}
}

/// <summary>
/// 鼠标按键放开事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MyText_MouseUp(object sender, MouseEventArgs e)
{
DragState = false;
}
/// <summary>
/// 鼠标按键按下事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MyText_MouseDown(object sender, MouseEventArgs e)
{
// throw new NotImplementedException();
if (!EditOrRun & !my_pp.Lock)
{
//编辑时
if (((ElementClass)sender).Width * 0.2 < e.X
& e.X < ((ElementClass)sender).Width * 0.8
& ((ElementClass)sender).Height * 0.2 < e.Y
& e.Y < ((ElementClass)sender).Height * 0.8)//确认光标位置是否在控件中心
{
//UIDesign.frmChild f = (UIDesign.frmChild)(((UIDesign)this.TopLevelControl).ActiveMdiChild);
if (!DeviceInterface.ProjectResources .projectResources .keyState .shift)
{
DragState = true;//拖动状态
mouse_offset = new Point(-e.X, -e.Y);
}
else
{
DoDragDrop(this, DragDropEffects.Move);
}
}

}
}
/// <summary>
///鼠标移动事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MyText_MouseMove(object sender, MouseEventArgs e)
{
if (!EditOrRun & DragState)
{
Point mousePos = Control.MousePosition;

if (e.Button == MouseButtons.Left)
{
mousePos.Offset(mouse_offset.X, mouse_offset.Y);
((Control)sender).Location = ((Control)sender).Parent.PointToClient(mousePos);
}
my_pp.Rectangle.Location = this.Location;
this.Invalidate();

}
}
/// <summary>
/// 双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MyText_DoubleClick(object sender, EventArgs e)
{

// throw new NotImplementedException();
if (!EditOrRun)//在编辑时双击打开属性窗口
{
my_pp.Rectangle.Location = this.Location;//保存位置
my_pp.Rectangle.Size = this.Size;
PropertyForm PF = new PropertyForm(my_pp);//实例化窗口
//((Form)(((Control)sender).Parent)).Controls.Add(PF);
PF.Location = new Point(600, 300);// new System.Drawing.Point((Screen.PrimaryScreen.Bounds.Width - this.Width) / 2, (Screen.PrimaryScreen.Bounds.Height - this.Height) / 2);
if (PF.ShowDialog() == DialogResult.OK)
{//显示窗口
// MessageBox.Show(PF.Location.ToString());
try
{
my_pp = PF.ppf;//回存数据

this.Size = my_pp.Rectangle.Size;//更新控件大小与位置
this.Location = my_pp.Rectangle.Location;
if (my_pp.DataImage != null & my_pp.DataImage != "")
//this.Image = MYRespirces.GetImage(my_pp.DataImage);
this.Image = DeviceInterface.ProjectResources .projectResources .myRespircescs.GetImage(my_pp.DataImage);
this.BackColor = my_pp.BGColor;
}
catch (Exception ex)
{
DeviceInterface.ProjectResources.projectResources.logHelper.WriteLine("MyText类双击函数错误");
}

 

}
PF.Dispose();//释放不要窗体控件内存
//this.OnPaint( new PaintEventArgs (this.CreateGraphics(),new Rectangle (0,0,this.Width ,this.Height )));
this.Invalidate(true);
}
}

private void MyText_SizeChanged(object sender, EventArgs e)
{
int l = (int)((float)this.Height * 0.43);
this.Font = new Font("宋体", l, FontStyle.Regular);


}

private void MyText_Click(object sender, EventArgs e)
{


}

protected override bool ProcessDialogKey(Keys keyData)
{
//text = text + Char.ConvertFromUtf32((int)keyData);
//this.Invalidate();
return base.ProcessDialogKey(keyData);

}
protected override void OnGotFocus(EventArgs e)
{
if (er)
{
this.Parent.Focus();
}
else
{
base.OnGotFocus(e);
Invalidate(false);
// this.BorderStyle = BorderStyle.FixedSingle;
}

}
protected override bool CanEnableIme
{
get
{
return true;
}
}
protected override void OnLostFocus(EventArgs e)
{
base.OnLostFocus(e);
Invalidate(false);

this.BorderStyle = BorderStyle.None;
}
public override bool Focused
{
get
{
return false;
}
}

protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base.OnPaint(e);
string Testr = this.text + my_pp.StrUnit;
Image IM = this.Image != null ? this.Image : (Image)Properties.Resources.ResourceManager.GetObject("TextBox");
Bitmap BIp = new Bitmap(this.Width, this.Height);
Graphics Bgh = Graphics.FromImage(BIp);


Rectangle destRect = new Rectangle(0, 0, this.Width, this.Height);
Rectangle destRectIM = new Rectangle(0, 0, IM.Width, IM.Height);
Bgh.DrawRectangle(new Pen(Color.Yellow), destRect);

Bgh.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
Bgh.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//int data = (int)(Font.Size * 1.3f) * Testr.Length;
//Bgh.DrawString(Testr, this.Font, new SolidBrush(this.my_pp.fontColor), new RectangleF((Math.Abs(Width - data) * 3 / 4) / 2 + Font.Size / 2, Math .Abs (Height - (int)(Font.Size * 1.3)) / 2, data, (int)(Font.Size * 1.3f) + 2));
//RectangleF RLf = new RectangleF((Width - data / 2) / 2 * 3 / 4, Math.Abs(Height - (int)(Font.Size * 1.3)) / 2, data, (int)(Font.Size * 1.3f) + 2);
SizeF vSizeF = e.Graphics.MeasureString(Testr, Font);
RectangleF RLf = new RectangleF((this.Width - vSizeF.Width) / 2, (this.Height - vSizeF.Height + 4) / 2, vSizeF.Width, vSizeF.Height);
Bgh.DrawString(Testr, this.Font, new SolidBrush(this.my_pp.fontColor), RLf);
Bgh.DrawImage(IM, destRect, destRectIM, System.Drawing.GraphicsUnit.Pixel);

e.Graphics.DrawImage(BIp, new Point(0, 0));

 


}

}
}

 

  

posted on 2018-03-18 22:13  xingbeiSoftware  阅读(307)  评论(0)    收藏  举报

导航