PictureBoxControl.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System.ComponentModel;
  2. using System.Windows.Forms;
  3. using System.Drawing;
  4. using FastReport.Utils;
  5. using System.Drawing.Drawing2D;
  6. namespace FastReport.Dialog
  7. {
  8. /// <summary>
  9. /// Represents a Windows picture box control for displaying an image.
  10. /// Wraps the <see cref="System.Windows.Forms.PictureBox"/> control.
  11. /// </summary>
  12. public partial class PictureBoxControl : DialogControl
  13. {
  14. private PictureBox pictureBox;
  15. #region Properties
  16. /// <summary>
  17. /// Gets an internal <b>PictureBox</b>.
  18. /// </summary>
  19. [Browsable(false)]
  20. public PictureBox PictureBox
  21. {
  22. get { return pictureBox; }
  23. }
  24. /// <summary>
  25. /// Indicates the border style for the control.
  26. /// Wraps the <see cref="System.Windows.Forms.PictureBox.BorderStyle"/> property.
  27. /// </summary>
  28. [DefaultValue(BorderStyle.None)]
  29. [Category("Appearance")]
  30. public BorderStyle BorderStyle
  31. {
  32. get { return PictureBox.BorderStyle; }
  33. set { PictureBox.BorderStyle = value; }
  34. }
  35. /// <summary>
  36. /// Gets or sets the image that the PictureBox displays.
  37. /// Wraps the <see cref="System.Windows.Forms.PictureBox.Image"/> property.
  38. /// </summary>
  39. [Category("Appearance")]
  40. public Image Image
  41. {
  42. get { return PictureBox.Image; }
  43. set { PictureBox.Image = value; }
  44. }
  45. /// <summary>
  46. /// Indicates how the image is displayed.
  47. /// Wraps the <see cref="System.Windows.Forms.PictureBox.SizeMode"/> property.
  48. /// </summary>
  49. [DefaultValue(PictureBoxSizeMode.Normal)]
  50. [Category("Behavior")]
  51. public PictureBoxSizeMode SizeMode
  52. {
  53. get { return PictureBox.SizeMode; }
  54. set { PictureBox.SizeMode = value; }
  55. }
  56. #endregion
  57. #region Public Methods
  58. /// <inheritdoc/>
  59. public override void Serialize(FRWriter writer)
  60. {
  61. PictureBoxControl c = writer.DiffObject as PictureBoxControl;
  62. base.Serialize(writer);
  63. if (BorderStyle != c.BorderStyle)
  64. writer.WriteValue("BorderStyle", BorderStyle);
  65. if (!writer.AreEqual(Image, c.Image))
  66. writer.WriteValue("Image", Image);
  67. if (SizeMode != c.SizeMode)
  68. writer.WriteValue("SizeMode", SizeMode);
  69. }
  70. public override void Draw(FRPaintEventArgs e)
  71. {
  72. base.Draw(e);
  73. Pen pen = e.Cache.GetPen(Color.Gray, 1, DashStyle.Dash);
  74. e.Graphics.DrawRectangle(pen, AbsLeft, AbsTop, Width - 1, Height - 1);
  75. }
  76. #endregion
  77. /// <summary>
  78. /// Initializes a new instance of the <b>PictureBoxControl</b> class with default settings.
  79. /// </summary>
  80. public PictureBoxControl()
  81. {
  82. pictureBox = new PictureBox();
  83. Control = pictureBox;
  84. }
  85. }
  86. }