123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using WWPipeLine.MapBasic.Conditions;
- using WeifenLuo.WinFormsUI.Docking;
- using SuperMap.UI;
- using WWPipeLine.MapBasic;
- using SuperMap.Data;
- using WWPipeLine.Commons;
- namespace WWPipeLine.MapTools.Conditions.XiTongGuanLi
- {
- public partial class BiaoZhuFengGe : ConditionPanel
- {
- private TextStyle ts = new TextStyle();
- private Recordset _rd;
- private int _rdsmid = 0;
- public BiaoZhuFengGe()
- {
- this.ConditionPanelName = "标注风格配置";
- InitializeComponent();
- this.IsShowResultWindow = false;
- }
- protected override void OnLoad(EventArgs e)
- {
- cbColor.DrawMode = DrawMode.OwnerDrawFixed;
- cbColor.Items.Add(Color.Red);
- cbColor.Items.Add(Color.Green);
- cbColor.Items.Add(Color.Brown);
- cbColor.Items.Add(Color.Black);
- cbColor.Items.Add(Color.Yellow);
- //FontFamily[] fs = FontFamily.Families;
- QueryParameter queryParameter = new QueryParameter
- {
- AttributeFilter = " pzlx='标注风格配置' ",
- ResultFields = new string[] { "smid", "pzlx", "pzKey", "pzValue" },
- CursorType = CursorType.Dynamic
- };
- _rd = ComsStatic.dvJSLK_PZ.Query(queryParameter);
- if (_rd.RecordCount != 1)
- {
- _rd.DeleteAll();
- _rd.AddNew(new GeoPoint(0, 0));
- _rd.SetFieldValue("pzlx", "标注风格配置");
- _rd.SetFieldValue("pzKey", "TextStyleKey");
- _rd.Update();
- _rd = ComsStatic.dvJSLK_PZ.Query(queryParameter);
- }
- _rdsmid = ComsStatic.StringToInt(_rd.GetFieldValue("smid"));
- bool fromResult = ts.FromXML(_rd.GetFieldValue("pzValue")?.ToString());
- if (fromResult)
- {
- uicbBold.Checked = ts.Bold;
- uicbUnderline.Checked = ts.Underline;
- uicbItalic.Checked = ts.Italic;
- uicbxSize.SelectedItem = ts.FontHeight.ToString();
- uicbxZiti.SelectedItem = ts.FontName;
- cbColor.SelectedIndex = ColorToComboxIndex(ts.ForeColor);
- }
- else
- {
- uicbxSize.SelectedIndex = 0; uicbxZiti.SelectedIndex = 0; cbColor.SelectedIndex = 0;
- }
- }
- public override object Do(DockPanel dockPanel = null)
- {
- ts.Bold = uicbBold.Checked;
- ts.Underline = uicbUnderline.Checked;
- ts.Italic = uicbItalic.Checked;
- ts.FontHeight = ComsStatic.StringToDouble(uicbxSize.SelectedItem);
- ts.FontName = uicbxZiti.SelectedItem.ToString();
- ts.Alignment = SuperMap.Data.TextAlignment.BottomLeft;
- if (_rd.SeekID(_rdsmid) || _rdsmid == 0)
- {
- _rd.Edit();
- _rd.SetFieldValue("pzValue", ts.ToXML());
- bool result = _rd.Update();
- ComsStatic.ShowUIMessageTipOKorError(result, "标注风格配置");
- }
- else
- { Sunny.UI.UIMessageTip.ShowError("信息在编辑选择时失败!"); }
- return true;
- }
- private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
- {
- //选中项
- e.DrawBackground();
- e.DrawFocusRectangle();
- if (e.Index < 0) return;
- ComboBox cmb = (ComboBox)sender;
- Color color = (Color)cmb.Items[e.Index];
- //画笔
- SolidBrush brush = new SolidBrush(color);
- Graphics g = e.Graphics;
- Rectangle rect = e.Bounds;
- rect.Inflate(-2, -2);
- Rectangle rectColor = new Rectangle(rect.Location, new Size(100, rect.Height));
- //绘制边框
- g.DrawRectangle(new Pen(e.ForeColor), rectColor);
- //填充颜色
- g.FillRectangle(brush, rectColor);
- //绘制文本
- g.DrawString(ColorToChineseString(color), new Font("宋体", 12), new SolidBrush(e.ForeColor), (rect.X + 100), rect.Y);
- }
- private string ColorToChineseString(Color color)
- {
- if (color == Color.Red) return "红色";
- if (color == Color.Green) return "绿色";
- if (color == Color.Brown) return "棕色";
- if (color == Color.Black) return "黑色";
- if (color == Color.Yellow) return "黄色";
- return "";
- }
- private int ColorToComboxIndex(Color color)
- {
- if (color.ToArgb() == Color.Red.ToArgb()) return 0;
- if (color.ToArgb() == Color.Green.ToArgb()) return 1;
- if (color.ToArgb() == Color.Brown.ToArgb()) return 2;
- if (color.ToArgb() == Color.Black.ToArgb()) return 3;
- if (color.ToArgb() == Color.Yellow.ToArgb()) return 4;
- return 0;
- }
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- ts.ForeColor = (Color)cbColor.SelectedItem;
- uilbDemo.ForeColor = ts.ForeColor;
- }
- private void uicbxZiti_SelectedIndexChanged(object sender, EventArgs e)
- {
- try
- {
- FontFamily fm = new FontFamily(uicbxZiti.SelectedItem.ToString());
- uilbDemo.Font = new Font(fm, ComsStatic.StringToFloat(uicbxSize.SelectedItem), GraphicsUnit.Millimeter);
- }
- catch { }
- }
- private void uicbxSize_SelectedIndexChanged(object sender, EventArgs e)
- {
- try
- {
- FontFamily fm = new FontFamily(uicbxZiti.SelectedItem.ToString());
- uilbDemo.Font = new Font(fm, ComsStatic.StringToFloat(uicbxSize.SelectedItem), GraphicsUnit.Millimeter);
- }
- catch { }
- }
- }
- }
|