BiaoZhuFengGe.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 WWPipeLine.MapBasic.Conditions;
  11. using WeifenLuo.WinFormsUI.Docking;
  12. using SuperMap.UI;
  13. using WWPipeLine.MapBasic;
  14. using SuperMap.Data;
  15. using WWPipeLine.Commons;
  16. namespace WWPipeLine.MapTools.Conditions.XiTongGuanLi
  17. {
  18. public partial class BiaoZhuFengGe : ConditionPanel
  19. {
  20. private TextStyle ts = new TextStyle();
  21. private Recordset _rd;
  22. private int _rdsmid = 0;
  23. public BiaoZhuFengGe()
  24. {
  25. this.ConditionPanelName = "标注风格配置";
  26. InitializeComponent();
  27. this.IsShowResultWindow = false;
  28. }
  29. protected override void OnLoad(EventArgs e)
  30. {
  31. cbColor.DrawMode = DrawMode.OwnerDrawFixed;
  32. cbColor.Items.Add(Color.Red);
  33. cbColor.Items.Add(Color.Green);
  34. cbColor.Items.Add(Color.Brown);
  35. cbColor.Items.Add(Color.Black);
  36. cbColor.Items.Add(Color.Yellow);
  37. //FontFamily[] fs = FontFamily.Families;
  38. QueryParameter queryParameter = new QueryParameter
  39. {
  40. AttributeFilter = " pzlx='标注风格配置' ",
  41. ResultFields = new string[] { "smid", "pzlx", "pzKey", "pzValue" },
  42. CursorType = CursorType.Dynamic
  43. };
  44. _rd = ComsStatic.dvJSLK_PZ.Query(queryParameter);
  45. if (_rd.RecordCount != 1)
  46. {
  47. _rd.DeleteAll();
  48. _rd.AddNew(new GeoPoint(0, 0));
  49. _rd.SetFieldValue("pzlx", "标注风格配置");
  50. _rd.SetFieldValue("pzKey", "TextStyleKey");
  51. _rd.Update();
  52. _rd = ComsStatic.dvJSLK_PZ.Query(queryParameter);
  53. }
  54. _rdsmid = ComsStatic.StringToInt(_rd.GetFieldValue("smid"));
  55. bool fromResult = ts.FromXML(_rd.GetFieldValue("pzValue")?.ToString());
  56. if (fromResult)
  57. {
  58. uicbBold.Checked = ts.Bold;
  59. uicbUnderline.Checked = ts.Underline;
  60. uicbItalic.Checked = ts.Italic;
  61. uicbxSize.SelectedItem = ts.FontHeight.ToString();
  62. uicbxZiti.SelectedItem = ts.FontName;
  63. cbColor.SelectedIndex = ColorToComboxIndex(ts.ForeColor);
  64. }
  65. else
  66. {
  67. uicbxSize.SelectedIndex = 0; uicbxZiti.SelectedIndex = 0; cbColor.SelectedIndex = 0;
  68. }
  69. }
  70. public override object Do(DockPanel dockPanel = null)
  71. {
  72. ts.Bold = uicbBold.Checked;
  73. ts.Underline = uicbUnderline.Checked;
  74. ts.Italic = uicbItalic.Checked;
  75. ts.FontHeight = ComsStatic.StringToDouble(uicbxSize.SelectedItem);
  76. ts.FontName = uicbxZiti.SelectedItem.ToString();
  77. ts.Alignment = SuperMap.Data.TextAlignment.BottomLeft;
  78. if (_rd.SeekID(_rdsmid) || _rdsmid == 0)
  79. {
  80. _rd.Edit();
  81. _rd.SetFieldValue("pzValue", ts.ToXML());
  82. bool result = _rd.Update();
  83. ComsStatic.ShowUIMessageTipOKorError(result, "标注风格配置");
  84. }
  85. else
  86. { Sunny.UI.UIMessageTip.ShowError("信息在编辑选择时失败!"); }
  87. return true;
  88. }
  89. private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
  90. {
  91. //选中项
  92. e.DrawBackground();
  93. e.DrawFocusRectangle();
  94. if (e.Index < 0) return;
  95. ComboBox cmb = (ComboBox)sender;
  96. Color color = (Color)cmb.Items[e.Index];
  97. //画笔
  98. SolidBrush brush = new SolidBrush(color);
  99. Graphics g = e.Graphics;
  100. Rectangle rect = e.Bounds;
  101. rect.Inflate(-2, -2);
  102. Rectangle rectColor = new Rectangle(rect.Location, new Size(100, rect.Height));
  103. //绘制边框
  104. g.DrawRectangle(new Pen(e.ForeColor), rectColor);
  105. //填充颜色
  106. g.FillRectangle(brush, rectColor);
  107. //绘制文本
  108. g.DrawString(ColorToChineseString(color), new Font("宋体", 12), new SolidBrush(e.ForeColor), (rect.X + 100), rect.Y);
  109. }
  110. private string ColorToChineseString(Color color)
  111. {
  112. if (color == Color.Red) return "红色";
  113. if (color == Color.Green) return "绿色";
  114. if (color == Color.Brown) return "棕色";
  115. if (color == Color.Black) return "黑色";
  116. if (color == Color.Yellow) return "黄色";
  117. return "";
  118. }
  119. private int ColorToComboxIndex(Color color)
  120. {
  121. if (color.ToArgb() == Color.Red.ToArgb()) return 0;
  122. if (color.ToArgb() == Color.Green.ToArgb()) return 1;
  123. if (color.ToArgb() == Color.Brown.ToArgb()) return 2;
  124. if (color.ToArgb() == Color.Black.ToArgb()) return 3;
  125. if (color.ToArgb() == Color.Yellow.ToArgb()) return 4;
  126. return 0;
  127. }
  128. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  129. {
  130. ts.ForeColor = (Color)cbColor.SelectedItem;
  131. uilbDemo.ForeColor = ts.ForeColor;
  132. }
  133. private void uicbxZiti_SelectedIndexChanged(object sender, EventArgs e)
  134. {
  135. try
  136. {
  137. FontFamily fm = new FontFamily(uicbxZiti.SelectedItem.ToString());
  138. uilbDemo.Font = new Font(fm, ComsStatic.StringToFloat(uicbxSize.SelectedItem), GraphicsUnit.Millimeter);
  139. }
  140. catch { }
  141. }
  142. private void uicbxSize_SelectedIndexChanged(object sender, EventArgs e)
  143. {
  144. try
  145. {
  146. FontFamily fm = new FontFamily(uicbxZiti.SelectedItem.ToString());
  147. uilbDemo.Font = new Font(fm, ComsStatic.StringToFloat(uicbxSize.SelectedItem), GraphicsUnit.Millimeter);
  148. }
  149. catch { }
  150. }
  151. }
  152. }