ImageItem.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. 
  2. using System;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. namespace Dongke.WinForm.Controls.InvoiceLayout
  6. {
  7. /// <summary>
  8. ///
  9. /// </summary>
  10. [Serializable]
  11. public class ImageItem : LayoutItem
  12. {
  13. #region 成员变量
  14. private string _fileName = string.Empty; // 图片文件的路径(全名)
  15. private Image _image; // 图片
  16. #endregion 成员变量
  17. #region 属性
  18. /// <summary>
  19. /// 获取或设置图片文件的路径(全名)
  20. /// </summary>
  21. public string FileName
  22. {
  23. get
  24. {
  25. return _fileName;
  26. }
  27. set
  28. {
  29. if (string.IsNullOrEmpty(value))
  30. {
  31. value = string.Empty;
  32. }
  33. if (!value.Equals(_fileName))
  34. {
  35. _fileName = value;
  36. if (Owner != null)
  37. {
  38. Owner.SetItemChangedArgs(this, ItemChangeType.Modified);
  39. }
  40. }
  41. }
  42. }
  43. /// <summary>
  44. /// 获取或设置图片
  45. /// </summary>
  46. public Image Image
  47. {
  48. get
  49. {
  50. return _image;
  51. }
  52. set
  53. {
  54. _image = value;
  55. if (SimpleShape != null)
  56. {
  57. SimpleShape.BackgroundImageLayout = ImageLayout.Stretch;
  58. SimpleShape.BackgroundImage = _image;
  59. }
  60. if (Owner != null)
  61. {
  62. Owner.SetItemChangedArgs(this, ItemChangeType.Modified);
  63. }
  64. }
  65. }
  66. #endregion 属性
  67. #region 构造函数
  68. /// <summary>
  69. /// 构造函数
  70. /// </summary>
  71. internal ImageItem()
  72. : this(null)
  73. {
  74. }
  75. /// <summary>
  76. /// 构造函数
  77. /// </summary>
  78. /// <param name="box">Layoutbox</param>
  79. internal ImageItem(LayoutBox box)
  80. : base(box, ItemType.Image)
  81. {
  82. _width = LayoutConsts.SHAPE_ITEM_SIZE_DEFAULT_WIDTH;
  83. _height = LayoutConsts.SHAPE_ITEM_SIZE_DEFAULT_HEIGHT;
  84. if (box != null)
  85. {
  86. if (_simpleShape != null)
  87. {
  88. _simpleShape.BackgroundImageLayout = ImageLayout.Stretch;
  89. _simpleShape.BackgroundImage = _image;
  90. }
  91. }
  92. }
  93. #endregion 构造函数
  94. #region 函数
  95. /// <summary>
  96. /// 显示Item属性设置画面
  97. /// </summary>
  98. /// <returns>
  99. /// DialogResult.OK:选中的Item有效,设置成功<br/>
  100. /// DialogResult.Cancel:选中的Item有效,取消设置<br/>
  101. /// DialogResult.None:LayoutBox不是编辑模式,或选中的Item不是一个
  102. /// </returns>
  103. protected override DialogResult ShowItemPropertyDialogInner()
  104. {
  105. using (ImageItemSetting itemPropertySetting = new ImageItemSetting())
  106. {
  107. itemPropertySetting.ImageLocationX = Left;
  108. itemPropertySetting.ImageLocationY = Top;
  109. itemPropertySetting.ImageWidth = Width;
  110. itemPropertySetting.ImageHeight = Height;
  111. itemPropertySetting.SideRatioFixed = SideRatioFixed;
  112. itemPropertySetting.FileName = FileName;
  113. itemPropertySetting.Image = Image;
  114. DialogResult result = itemPropertySetting.ShowDialog();
  115. if (result == DialogResult.OK)
  116. {
  117. Left = itemPropertySetting.ImageLocationX;
  118. Top = itemPropertySetting.ImageLocationY;
  119. Width = itemPropertySetting.ImageWidth;
  120. Height = itemPropertySetting.ImageHeight;
  121. SideRatioFixed = itemPropertySetting.SideRatioFixed;
  122. ResetItemFrame();
  123. SetDrawProperty();
  124. Owner.Dirty = true;
  125. }
  126. return result;
  127. }
  128. }
  129. /// <summary>
  130. /// Item初始化
  131. /// </summary>
  132. /// <param name="box">LayoutBox</param>
  133. /// <param name="isNewID">是否生成新ID</param>
  134. /// <returns>是否成功</returns>
  135. internal override bool Init(LayoutBox box, bool isNewID)
  136. {
  137. bool isInit = base.Init(box, isNewID);
  138. if (isInit)
  139. {
  140. if (_simpleShape != null)
  141. {
  142. _simpleShape.BackgroundImageLayout = ImageLayout.Stretch;
  143. _simpleShape.BackgroundImage = _image;
  144. }
  145. }
  146. return isInit;
  147. }
  148. #endregion 函数
  149. }
  150. }