using System;using System.Windows.Forms;namespace GDIPrinterDriver{ /// /// 模板元素接口 /// public interface ILabelDesignElement { /// /// PrintData/codeContext里的字段,{} [] /// string 动态内容 { get; set; } /// /// 是否被选中 /// bool DesignSelected { get; set; } /// /// 选择状态发生改变 /// event Action
using GDIPrinterDriver;using System;using System.ComponentModel;using System.Drawing;using System.Drawing.Drawing2D;using System.Drawing.Imaging;using System.Windows.Forms;namespace GDILabelDesigner{ /// /// 设计时控件基类 /// public abstract class DesignCellControl : PictureBox, ILabelDesignElement { #region 鼠标移动和缩放 private enum EnumMousePointPosition { MouseSizeNone = 0, //'无 MouseSizeRight = 1, //'拉伸右边框 MouseSizeLeft = 2, //'拉伸左边框 MouseSizeBottom = 3, //'拉伸下边框 MouseSizeTop = 4, //'拉伸上边框 MouseSizeTopLeft = 5, //'拉伸左上角 MouseSizeTopRight = 6, //'拉伸右上角 MouseSizeBottomLeft = 7, //'拉伸左下角 MouseSizeBottomRight = 8, //'拉伸右下角 MouseDrag = 9 // '鼠标拖动 } const int Band = 5; const int MinWidth = 10; const int MinHeight = 10; private EnumMousePointPosition m_MousePointPosition; private Point p, p1; private EnumMousePointPosition MousePointPosition(Size size, System.Windows.Forms.MouseEventArgs e) { if ((e.X >= -1 * Band) | (e.X <= size.Width) | (e.Y >= -1 * Band) | (e.Y <= size.Height)) { if (e.X < Band) { if (e.Y < Band) { return EnumMousePointPosition.MouseSizeTopLeft; } else { if (e.Y > -1 * Band + size.Height) { return EnumMousePointPosition.MouseSizeBottomLeft; } else { return EnumMousePointPosition.MouseSizeLeft; } } } else { if (e.X > -1 * Band + size.Width) { if (e.Y < Band) { return EnumMousePointPosition.MouseSizeTopRight; } else { if (e.Y > -1 * Band + size.Height) { return EnumMousePointPosition.MouseSizeBottomRight; } else { return EnumMousePointPosition.MouseSizeRight; } } } else { if (e.Y < Band) { return EnumMousePointPosition.MouseSizeTop; } else { if (e.Y > -1 * Band + size.Height) { return EnumMousePointPosition.MouseSizeBottom; } else { return EnumMousePointPosition.MouseDrag; } } } } } else { return EnumMousePointPosition.MouseSizeNone; } } #endregion public bool DesignSelected { get { return designSelected; } set { designSelected = value; Invalidate(); } } private bool designSelected = false; public DynamicMapProperty DynamicMapProperty { get; set; } public StaticMapProperty StaticMapProperty { get; set; } public string 动态内容 { get; set; } public RoteDescription RoteDescription { get; set; } /// /// 被选中,获取到焦点的事件 /// public event Action