⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 picturebox.cs

📁 是用c#实现的一个有关于报表设计的程序代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
#region License
/*
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option)
any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to
the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
*/
#endregion

using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Xml;


namespace daReport
{
	/// <summary>
	/// Class representing the PictureBox object.
	/// </summary>
	/// <remarks>The PictureBox is used in reports where images need to be displayed.
	/// Compay logo, background image, etc. A background image can be combined with the
	/// <see cref="daReport.PictureBox.Selectable">daReport.PictureBox.Selectable</see> property
	/// so it can't be selected in the Designer Application.
	/// </remarks>
	public class PictureBox : ICustomPaint
	{
		#region Declarations
		private Bitmap mImage;
		private Rectangle mRegion;
		private bool mDoStretch = false;
		private Color mBorderColor = Color.Black;
		private int mBorderWidth = 0;
		private string mFilename = "";
		private bool mSelectable = true;
		#endregion

		#region Public Properties

		/// <summary>
		/// Gets/Sets the border color for the PictureBox
		/// </summary>
		/// <remarks>This property sets the border color of the PictureBox object. This can be any color
		/// from the System.Drawing.Color structure
		/// </remarks>
		public Color BorderColor
		{
			get {return mBorderColor;}
			set {mBorderColor = value;}
		}


		/// <summary>
		/// Gets/Sets the border width for the PictureBox
		/// </summary>
		/// <remarks>
		/// BorderWidth of the PictureBox. If this is set to zero, then the border is invisible
		/// </remarks>
		public int BorderWidth
		{
			get {return mBorderWidth;}
			set {mBorderWidth = value;}
		}


		/// <summary>
		/// Location of image file relative to xml template file.
		/// </summary>
		/// <remarks>For new documents defaults to working directory of Designer.</remarks>
		[Description("Image file location relative to .xml file. For new documents defaults to working directory of Designer.")]
		public string ImageFile
		{
			get {return mFilename;}
			set
			{
				if (value != null)
					Load(value);
			}
		}


		/// <summary>
		/// Stretch the image to the container size.
		/// </summary>
		/// <remarks>
		/// If set to true, the image to the container size, otherwise will be displayed as it's physical size.
		/// </remarks>
		[Description("Stretch the image to the container size.")]
		public bool Stretch
		{
			get {return mDoStretch;}
			set {mDoStretch = value;}
		}


		#endregion

		#region Public Overrides

		/// <summary>
		/// This function adds the current objects information to the XmlTextWriter
		/// </summary>
		/// <param name="CurrentWriter">Current XmlTextWriter to append object information to</param>
		public override void AddXMLToWriter(ref System.Xml.XmlTextWriter CurrentWriter)
		{
			CurrentWriter.WriteStartElement("pictureBox");
			CurrentWriter.WriteAttributeString("x", this.X.ToString());
			CurrentWriter.WriteAttributeString("y", this.Y.ToString());
			CurrentWriter.WriteAttributeString("width", this.Width.ToString());
			CurrentWriter.WriteAttributeString("height", this.Height.ToString());
			CurrentWriter.WriteAttributeString("stretch", this.mDoStretch.ToString());
			CurrentWriter.WriteAttributeString("horAlignment", this.horizontalAlignment.ToString());
			CurrentWriter.WriteAttributeString("verAlignment", this.verticalAlignment.ToString());
			CurrentWriter.WriteAttributeString("Selectable", this.mSelectable.ToString());
			CurrentWriter.WriteAttributeString("ObjectRepeatability", this.objectRepeatability.ToString());
			CurrentWriter.WriteStartElement("file");
			CurrentWriter.WriteString(Helpers.TextSafeForXML(this.mFilename));
			CurrentWriter.WriteEndElement(); //end of file element
			CurrentWriter.WriteStartElement("border");
			CurrentWriter.WriteAttributeString("width", this.mBorderWidth.ToString());
			CurrentWriter.WriteAttributeString("color", this.mBorderColor.Name);
			CurrentWriter.WriteEndElement(); //end of border element
			CurrentWriter.WriteEndElement(); //end of pictureBox element
		}


		/// <summary>
		/// Loads the current objects information from the XmlNode passed
		/// </summary>
		/// <param name="CurrentNode">XmlNode with objects information</param>
		public override void LoadFromXMLNode(System.Xml.XmlNode CurrentNode)
		{
			this.X = Convert.ToInt32(CurrentNode.Attributes["x"].Value);
			this.Y = Convert.ToInt32( CurrentNode.Attributes["y"].Value);
			this.Width = Convert.ToInt32( CurrentNode.Attributes["width"].Value );
			this.Height = Convert.ToInt32( CurrentNode.Attributes["height"].Value );

			if (CurrentNode.Attributes["horAlignment"] != null)
				this.horizontalAlignment = ICustomPaint.ResolveHorizontalAlignment(CurrentNode.Attributes["horAlignment"].Value);

			if (CurrentNode.Attributes["verAlignment"] != null)
				this.verticalAlignment = ICustomPaint.ResolveVerticalAlignment(CurrentNode.Attributes["verAlignment"].Value);

			if (CurrentNode.Attributes["Selectable"] != null)
				this.mSelectable = Convert.ToBoolean(CurrentNode.Attributes["Selectable"].Value);

			if (CurrentNode.Attributes["ObjectRepeatability"] != null)
				this.objectRepeatability = ICustomPaint.ResolveObjectRepeatability(CurrentNode.Attributes["ObjectRepeatability"].Value);

			bool doStretch = false;
			try
			{
				doStretch = CurrentNode.Attributes["stretch"]==null ? true : Convert.ToBoolean(CurrentNode.Attributes["stretch"].Value);
			}
			catch (Exception){}
			this.mDoStretch = doStretch;

			System.Xml.XmlNodeList childNodes = CurrentNode.ChildNodes;

			for (int i=0;i<childNodes.Count;i++)
			{
				switch (childNodes[i].Name)
				{
					case "file":
					
						this.Load(childNodes[i].InnerText);
						break;

					case "border":
						try
						{
							this.mBorderColor = Color.FromName( childNodes[i].Attributes["color"].Value );
							this.mBorderWidth = childNodes[i].Attributes["width"]==null ? 0 : Convert.ToInt32( childNodes[i].Attributes["width"].Value );
						}
						catch (Exception){}
						break;

				}

			}
		}


		/// <summary>
		/// The X coordinate of the left-upper corner of the PictureBox
		/// </summary>
		[Description("The X coordinate of the left-upper corner of the element.")]
		public override int X
		{
			get {return mRegion.X;}
			set 
			{
				if (this.HorizontalAlignment == ICustomPaint.HorizontalAlignmentTypes.None)
					mRegion.X = value;
				else if (this.HorizontalAlignment == ICustomPaint.HorizontalAlignmentTypes.Right)
				{
					mRegion.Width = mRegion.Width + mRegion.X - value;
					mRegion.X = value;					
				}
				else if (this.HorizontalAlignment == ICustomPaint.HorizontalAlignmentTypes.Center)
				{
					mRegion.Width = mRegion.Width + 2*(mRegion.X - value);
					mRegion.X = value;					
				}

			}
		}


		/// <summary>
		/// The Y coordinate of the left-upper corner of the PictureBox
		/// </summary>
		[Description("The Y coordinate of the left-upper corner of the element.")]
		public override int Y
		{
			get {return mRegion.Y;}
			set 
			{
				if (this.VerticalAlignment == ICustomPaint.VerticalAlignmentTypes.None)
					mRegion.Y = value;
				else if (this.VerticalAlignment == ICustomPaint.VerticalAlignmentTypes.Bottom)
				{
					mRegion.Height = mRegion.Height + mRegion.Y - value;
					mRegion.Y = value;					
				}
				else if (this.VerticalAlignment == ICustomPaint.VerticalAlignmentTypes.Middle)
				{
					mRegion.Height = mRegion.Height + 2*(mRegion.Y - value);
					mRegion.Y = value;					
				}
			}
		}


		/// <summary>
		///  Gets or sets the width of the PictureBox.
		/// </summary>
		[Description("The width of the element.")]
		public override int Width
		{
			get {return mRegion.Width;}
			set
			{
				if (this.HorizontalAlignment == ICustomPaint.HorizontalAlignmentTypes.None || this.HorizontalAlignment == ICustomPaint.HorizontalAlignmentTypes.Left)
					mRegion.Width = value;
				else if (this.HorizontalAlignment == ICustomPaint.HorizontalAlignmentTypes.Right)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -