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

📄 line.cs

📁 是用c#实现的一个有关于报表设计的程序代码
💻 CS
字号:
#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;


namespace daReport
{
	/// <summary>
	/// Class representing the Line object.
	/// </summary>
	/// <remarks>The Line is used to draw lines on the report.
	/// </remarks>
	public class Line : ICustomPaint
	{
		#region Declarations
		Color mLineColor = Color.Black;
		Rectangle mRegion = new Rectangle();
		bool mSelectable = true;
		#endregion

		#region Public Properties

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


		#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("line");
			CurrentWriter.WriteAttributeString("x", this.X.ToString());
			CurrentWriter.WriteAttributeString("y", this.Y.ToString());
			CurrentWriter.WriteAttributeString("height", this.Height.ToString());
			CurrentWriter.WriteAttributeString("width", this.Width.ToString());
			CurrentWriter.WriteAttributeString("lineColor", this.mLineColor.Name);
			CurrentWriter.WriteAttributeString("Selectable", this.mSelectable.ToString());
			CurrentWriter.WriteAttributeString("ObjectRepeatability", this.objectRepeatability.ToString());
			CurrentWriter.WriteEndElement(); //end of line element
		}


		/// <summary>
		///  Gets or sets the height of the PictureBox.
		/// </summary>
		[Browsable(false)]
		public override daReport.ICustomPaint.HorizontalAlignmentTypes HorizontalAlignment
		{
			get { return daReport.ICustomPaint.HorizontalAlignmentTypes.None; }
			set {}
		}


		/// <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.Height = Convert.ToInt32( CurrentNode.Attributes["height"].Value );
			this.Width= Convert.ToInt32( CurrentNode.Attributes["width"].Value );
			this.LineColour = Color.FromName(CurrentNode.Attributes["lineColor"].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);
		}


		/// <summary>
		///  Gets or sets the height of the Line
		/// </summary>
		[Category("Layout"), Description("The height of the element.")]
		public override int Height
		{
			get {return mRegion.Height;}
			set
			{
				if (this.VerticalAlignment == ICustomPaint.VerticalAlignmentTypes.None || this.VerticalAlignment == ICustomPaint.VerticalAlignmentTypes.Top)
					mRegion.Height = value;
				else if (this.VerticalAlignment == ICustomPaint.VerticalAlignmentTypes.Bottom)
				{
					mRegion.Y = mRegion.Y - value + mRegion.Height;
					mRegion.Height = value;									
				}
				else if (this.VerticalAlignment == ICustomPaint.VerticalAlignmentTypes.Middle)
				{
					mRegion.Y = mRegion.Y - value/2 + mRegion.Height/2;
					mRegion.Height = value;									
				}
			}
		}


		/// <summary>
		///  Gets or sets the Line repeatability over multiple pages
		/// </summary>
		/// <remarks>
		/// The Line's repeatability setting governs how whether it is repeated
		/// over multiple pages, only on the first page, or only on the last page.
		/// </remarks>
		[Description("This controls repeatability of the Line over multiple pages.")]
		public override daReport.ICustomPaint.ObjectRepeatabilityTypes ObjectRepeatability
		{
			set { this.objectRepeatability=value; }
			get { return this.objectRepeatability; }
		}


		/// <summary>
		///  Gets or sets the height of the Line.
		/// </summary>
		[Description("Sets whether the Line can be selected in the design pane.")]
		public override bool Selectable
		{
			set { this.mSelectable=value; }
			get { return this.mSelectable; }
		}

		
		/// <summary>
		///  Gets or sets the height of the PictureBox.
		/// </summary>
		[Browsable(false)]
		public override daReport.ICustomPaint.VerticalAlignmentTypes VerticalAlignment
		{
			get { return daReport.ICustomPaint.VerticalAlignmentTypes.None; }
			set {}
		}


		/// <summary>
		///  Gets or sets the width of the StyledTable.
		/// </summary>
		[Category("Layout"), 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)
				{
					mRegion.X = mRegion.X - value + mRegion.Width;
					mRegion.Width = value;									
				}
				else if (this.HorizontalAlignment == ICustomPaint.HorizontalAlignmentTypes.Center)
				{
					mRegion.X = mRegion.X - value/2 + mRegion.Width/2;
					mRegion.Width = value;									
				}
			}
		}


		/// <summary>
		///  Gets or sets the height of the PictureBox.
		/// </summary>
		[Description("The X coordinate of the left-upper corner of the element.")]
		public override int X
		{
			get { return this.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>
		///  Gets or sets the height of the PictureBox.
		/// </summary>
		[Description("The Y coordinate of the left-upper corner of the element.")]
		public override int Y
		{
			get { return this.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;					
				}
			}
		}


		#endregion

		#region ICustomPaint Members

		/// <summary>
		/// Paints the PictureBox
		/// </summary>
		/// <param name="g">The Graphics object to draw</param>
		/// <remarks>Causes the PictureBox to be painted to the screen.</remarks>
		public override void Paint(Graphics g)
		{
			g.DrawLine(new Pen(this.mLineColor, this.Height), this.mRegion.X, this.mRegion.Y+(this.Height/2), this.X+this.mRegion.Width, this.Y+(this.Height/2));
		}


		/// <summary>
		/// Gets the region of the current PictureBox
		/// </summary>
		/// <returns>System.Drawing.Rectangle</returns>
		public override Rectangle GetRegion()
		{
			return mRegion;
		}


		/// <summary>
		/// Clones the structure of the PictureBox, including all properties
		/// </summary>
		/// <returns><see cref="daReport.ChartBox">daReport.ChartBox</see></returns>
		public override object Clone()
		{
			Line tmp = new Line(0, 0, 0, 0, document);
			tmp.X = this.X;
			tmp.Y = this.Y;
			tmp.Height = this.Height;
			tmp.Width = this.Width;
			return tmp;
		}


		#endregion

		#region Creator

		/// <summary>
		/// Initializes a new instance of the Line class.
		/// </summary>
		/// <param name="X">x-position of the new Line</param>
		/// <param name="Y">y-position of the new Line</param>
		/// <param name="Width">width of the new Line</param>
		/// <param name="Height">height of the new Line</param>
		/// <param name="parent">Parent of the new Line</param>
		public Line(int X, int Y, int Width, int Height, DaPrintDocument parent)
		{
			this.mRegion = new Rectangle(X, Y, Width, Height);

			document = parent;
			this.X = X;
			this.Y = Y;
			this.Width = Height;
			this.Width = Width;
		}


		#endregion
	}
}

⌨️ 快捷键说明

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