BiaoZhuFengGe.cs 4.9 KB

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