| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
-
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- namespace Dongke.WinForm.Controls.InvoiceLayout
- {
- /// <summary>
- ///
- /// </summary>
- [Serializable]
- public class ImageItem : LayoutItem
- {
- #region 成员变量
- private string _fileName = string.Empty; // 图片文件的路径(全名)
- private Image _image; // 图片
- #endregion 成员变量
- #region 属性
- /// <summary>
- /// 获取或设置图片文件的路径(全名)
- /// </summary>
- public string FileName
- {
- get
- {
- return _fileName;
- }
- set
- {
- if (string.IsNullOrEmpty(value))
- {
- value = string.Empty;
- }
- if (!value.Equals(_fileName))
- {
- _fileName = value;
- if (Owner != null)
- {
- Owner.SetItemChangedArgs(this, ItemChangeType.Modified);
- }
- }
- }
- }
- /// <summary>
- /// 获取或设置图片
- /// </summary>
- public Image Image
- {
- get
- {
- return _image;
- }
- set
- {
- _image = value;
- if (SimpleShape != null)
- {
- SimpleShape.BackgroundImageLayout = ImageLayout.Stretch;
- SimpleShape.BackgroundImage = _image;
- }
- if (Owner != null)
- {
- Owner.SetItemChangedArgs(this, ItemChangeType.Modified);
- }
- }
- }
- #endregion 属性
- #region 构造函数
- /// <summary>
- /// 构造函数
- /// </summary>
- internal ImageItem()
- : this(null)
- {
- }
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="box">Layoutbox</param>
- internal ImageItem(LayoutBox box)
- : base(box, ItemType.Image)
- {
- _width = LayoutConsts.SHAPE_ITEM_SIZE_DEFAULT_WIDTH;
- _height = LayoutConsts.SHAPE_ITEM_SIZE_DEFAULT_HEIGHT;
- if (box != null)
- {
- if (_simpleShape != null)
- {
- _simpleShape.BackgroundImageLayout = ImageLayout.Stretch;
- _simpleShape.BackgroundImage = _image;
- }
- }
- }
- #endregion 构造函数
- #region 函数
- /// <summary>
- /// 显示Item属性设置画面
- /// </summary>
- /// <returns>
- /// DialogResult.OK:选中的Item有效,设置成功<br/>
- /// DialogResult.Cancel:选中的Item有效,取消设置<br/>
- /// DialogResult.None:LayoutBox不是编辑模式,或选中的Item不是一个
- /// </returns>
- protected override DialogResult ShowItemPropertyDialogInner()
- {
- using (ImageItemSetting itemPropertySetting = new ImageItemSetting())
- {
- itemPropertySetting.ImageLocationX = Left;
- itemPropertySetting.ImageLocationY = Top;
- itemPropertySetting.ImageWidth = Width;
- itemPropertySetting.ImageHeight = Height;
- itemPropertySetting.SideRatioFixed = SideRatioFixed;
- itemPropertySetting.FileName = FileName;
- itemPropertySetting.Image = Image;
- DialogResult result = itemPropertySetting.ShowDialog();
- if (result == DialogResult.OK)
- {
- Left = itemPropertySetting.ImageLocationX;
- Top = itemPropertySetting.ImageLocationY;
- Width = itemPropertySetting.ImageWidth;
- Height = itemPropertySetting.ImageHeight;
- SideRatioFixed = itemPropertySetting.SideRatioFixed;
- ResetItemFrame();
- SetDrawProperty();
- Owner.Dirty = true;
- }
- return result;
- }
- }
- /// <summary>
- /// Item初始化
- /// </summary>
- /// <param name="box">LayoutBox</param>
- /// <param name="isNewID">是否生成新ID</param>
- /// <returns>是否成功</returns>
- internal override bool Init(LayoutBox box, bool isNewID)
- {
- bool isInit = base.Init(box, isNewID);
- if (isInit)
- {
- if (_simpleShape != null)
- {
- _simpleShape.BackgroundImageLayout = ImageLayout.Stretch;
- _simpleShape.BackgroundImage = _image;
- }
- }
- return isInit;
- }
- #endregion 函数
- }
- }
|