WebfontLable.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Drawing.Text;
  11. using IntelligentControlForsx.ChildForms;
  12. using IntelligentControlForsx.Code;
  13. namespace IntelligentControlForsx.MyControls
  14. {
  15. public partial class WebfontLable : UserControl
  16. {
  17. public WebfontLable()
  18. {
  19. InitializeComponent();
  20. SetStyle(ControlStyles.UserPaint, true);
  21. SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  22. SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲  
  23. this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
  24. this.UpdateStyles();
  25. }
  26. public void Build()
  27. {
  28. switch (LableShowType)
  29. {
  30. case 0:
  31. {
  32. break;
  33. }
  34. case 1:
  35. {
  36. LableMessage.AddLabel(this);
  37. break;
  38. }
  39. case 2:
  40. {
  41. break;
  42. }
  43. case 3:
  44. {
  45. break;
  46. }
  47. default:
  48. {
  49. break;
  50. }
  51. }
  52. }
  53. [Browsable(true), Category("Appearance")]
  54. public string LableText
  55. {
  56. get { return this.label1.Text; }
  57. set { this.label1.Text = value; }
  58. }
  59. /// <summary>
  60. /// 0是场站,1是风机,2是升压站
  61. /// 0,不变化 1-3实时刷新
  62. /// </summary>
  63. [Browsable(true), Category("Appearance")]
  64. public int LableType
  65. {
  66. get;
  67. set;
  68. }
  69. /// <summary>
  70. /// 0是显示固定值,1根据ID显示实时数据,2根据统一编码显示数据,3根据赋值显示
  71. /// 0,不变化 1-3实时刷新
  72. /// </summary>
  73. [Browsable(true), Category("Appearance")]
  74. public int LableShowType
  75. {
  76. get;
  77. set;
  78. }
  79. /// <summary>
  80. /// 测点编码
  81. /// </summary>
  82. [Browsable(true), Category("Appearance")]
  83. public string TestPointId
  84. {
  85. get;
  86. set;
  87. }
  88. /// <summary>
  89. /// 统一编码
  90. /// </summary>
  91. [Browsable(true), Category("Appearance")]
  92. public string UniformCode
  93. {
  94. get;
  95. set;
  96. }
  97. /// <summary>
  98. /// 风机编码
  99. /// </summary>
  100. [Browsable(true), Category("Appearance")]
  101. public string WindTurbineId
  102. {
  103. get;
  104. set;
  105. }
  106. /// <summary>
  107. /// 风场编码
  108. /// </summary>
  109. [Browsable(true), Category("Appearance")]
  110. public string WindPowerId
  111. {
  112. get;
  113. set;
  114. }
  115. /// <summary>
  116. /// 字体大小
  117. /// </summary>
  118. [Browsable(true), Category("Appearance")]
  119. public float MyEmSize
  120. {
  121. set
  122. {
  123. this.label1.Font = new System.Drawing.Font("DS-Digital", value, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  124. }
  125. get
  126. {
  127. return this.label1.Font.Size;
  128. }
  129. }
  130. /// <summary>
  131. /// 字体位置
  132. /// </summary>
  133. [Browsable(true), Category("Appearance")]
  134. public DockStyle MyLabelDock
  135. {
  136. set
  137. {
  138. this.label1.Dock = value;
  139. }
  140. get
  141. {
  142. return this.label1.Dock;
  143. }
  144. }
  145. /// <summary>
  146. /// 字体位置
  147. /// </summary>
  148. [Browsable(true), Category("Appearance")]
  149. public ContentAlignment MyLabelTextAlign
  150. {
  151. set
  152. {
  153. this.label1.TextAlign = value;
  154. }
  155. get
  156. {
  157. return this.label1.TextAlign;
  158. }
  159. }
  160. private void WebfontLable_Load(object sender, EventArgs e)
  161. {
  162. this.Name = Guid.NewGuid().ToString();
  163. //this.label1.Font = new System.Drawing.Font("DS-Digital", 21.75F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  164. //this.label1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
  165. //string str1 = UserTools.Path + @"\fonts\webfont.ttf";
  166. ////读取字体文件
  167. //PrivateFontCollection pfc = new PrivateFontCollection();
  168. //pfc.AddFontFile(str1);
  169. ////实例化字体
  170. //Font f = new Font(pfc.Families[0], 21.75F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  171. ////设置字体
  172. //this.label1.Font = f;
  173. }
  174. public event EventHandler MyClick;
  175. private void label1_Click(object sender, EventArgs e)
  176. {
  177. PointLineForm form = null;
  178. if (!string.IsNullOrEmpty(ThingType) && !string.IsNullOrEmpty(ThingId) && !string.IsNullOrEmpty(UniformCodeString))
  179. form = new PointLineForm(ThingType, ThingId, UniformCodeString, PointName);
  180. else if (!string.IsNullOrEmpty(TagName))
  181. form = new PointLineForm(TagName, PointName);
  182. if (form != null)
  183. {
  184. form.StartPosition = FormStartPosition.CenterParent;
  185. form.ShowDialog();
  186. }
  187. if (MyClick != null)
  188. {
  189. MyClick(this, e);
  190. }
  191. }
  192. private void label1_MouseEnter(object sender, EventArgs e)
  193. {
  194. this.label1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
  195. }
  196. private void label1_MouseLeave(object sender, EventArgs e)
  197. {
  198. this.label1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
  199. }
  200. private string ThingType { set; get; }
  201. private string ThingId { set; get; }
  202. private string UniformCodeString { set; get; }
  203. private string TagName { set; get; }
  204. private string PointName { set; get; }
  205. /// <summary>
  206. /// 绑定数据
  207. /// </summary>
  208. /// <param name="pointValue">测点值</param>
  209. /// <param name="thingType">设备类型</param>
  210. /// <param name="thingId">设备编号</param>
  211. /// <param name="uniformcode">统一编码</param>
  212. /// <param name="nameString">统一编码含义</param>
  213. public void BindData(string pointValue, string thingType, string thingId, string uniformcode, string nameString)
  214. {
  215. this.LableText = pointValue;
  216. ThingType = thingType;
  217. ThingId = thingId;
  218. UniformCodeString = uniformcode;
  219. PointName = nameString;
  220. }
  221. /// <summary>
  222. /// 绑定数据
  223. /// </summary>
  224. /// <param name="pointValue">测点值</param>
  225. /// <param name="tagName">点名</param>
  226. /// <param name="nameString">测点名含义</param>
  227. public void BindData(string pointValue, string tagName, string nameString)
  228. {
  229. this.LableText = pointValue;
  230. TagName = tagName;
  231. PointName = nameString;
  232. }
  233. }
  234. }