|
|
Posted on
2004-12-08 12:51
冷风.net
阅读( 506)
评论()
收藏
举报
//*************************************************************************************************
//完成日期: 2004-11-29
//作者: 何利民
//程序功能: 設置繪圖區域
//*************************************************************************************************
using System;
using System.Drawing;
using System.Drawing.Text;
using System.Drawing.Imaging;
using System.ComponentModel;
namespace ImagesSpaceName
  {
 /**//// <summary>
/// 繪圖區域
/// </summary>
public class ImageArea : ImagesClass
 {
 定義類變量#region 定義類變量
protected float _width = 400; //圖片寬度
protected float _height = 400; //圖片高度
protected int _alpha=255; //圖片透明度
protected string _bgGround = null; //背景圖片
protected int _bgGroundAlpha=255; //背景圖片透明度
protected string _bgColor = "#ffffff"; //背景顏色
protected int _marginLeft = 10; //圖片左邊界大小
protected int _marginTop = 10; //圖片上邊界大小
protected int _marginRight=10; //圖片右邊界大小
protected int _marginBottom=10; //圖片下邊界大小
protected string _xyColor = "#000000"; //坐標軸的顏色
protected int _xySize = 1; //坐標軸的大小
protected string _xyFontColor = "#000000"; //坐標軸字體顏色
protected int _xyFontSize=12; //坐標軸字體大小
protected string _xyFontFamily = "新細明體"; //坐標軸字體名稱
protected bool _showXY=true; //顯示坐標軸
protected bool _showXYTitle=true; //顯示坐標軸的標題
protected bool _showPointTitle=true; //顯示坐標點的文字
protected bool _showXGrid=false; //顯示X向網絡
protected bool _showYGrid=false; //顯示Y向網格
protected int _gridLineSize=1; //網格線大小
protected string _gridLineColor="#000000"; //網格線顏色
protected Point topLeftDot; //繪圖區左上角的點
protected Point topRightDot; //繪圖區右上角的點
protected Point bottomLeftDot; //繪圖區左下角的點
protected Point bottomRightDot; //繪圖區右下角的點
protected Bitmap bitmap; //所繪圖片
protected Graphics graphics; //繪圖區
#endregion
 初使化構造函數#region 初使化構造函數
public ImageArea()
 {
}
#endregion
 定義屬性#region 定義屬性
[
Bindable(true),
Category("drawing"),
DefaultValue(ImagesSpaceName.WaterTitle.bottom),
Description("設置或獲得圖片的寬度")
]
public virtual float Width
 {
 get {return _width;}
set
 {
try
 {
_width = value;
}
catch(Exception exc)
 {
this.SetErrorInfo(ERRORSOURCE[0],"Width",exc.Message,ERRORINFO[0]);
throw new Exception(ERRORINFO[0]);
}
}
}
[
Bindable(true),
Category("drawing"),
DefaultValue(ImagesSpaceName.WaterTitle.bottom),
Description("設置或獲得圖片的高度")
]
public virtual float Height
 {
get
 {
return _height;
}
set
 {
try
 {
_height = value;
}
catch(Exception exc)
 {
this.SetErrorInfo(ERRORSOURCE[0],"Height",exc.Message,ERRORINFO[0]);
throw new Exception(ERRORINFO[0]);
}
}
}
[
Bindable(true),
Category("drawing"),
DefaultValue(ImagesSpaceName.WaterTitle.bottom),
Description("獲得或設置背景圖片")
]
public virtual string BgGround
 {
 get {return _bgGround;}
 set {_bgGround = value;}
}
[
Bindable(true),
Category("drawing"),
DefaultValue(ImagesSpaceName.WaterTitle.bottom),
Description("獲得或設置背景顏色")
]
public virtual string BgColor
 {
 get {return _bgColor;}
set
 {
_bgColor = value;
try
 {
Color c = ColorTranslator.FromHtml(_bgColor);
}
catch(Exception exc)
 {
this.SetErrorInfo(ERRORSOURCE[0],"BgColor",exc.Message,ERRORINFO[1]);
throw new Exception(ERRORINFO[1]);
}
}
}
[
Bindable(true),
Category("drawing"),
DefaultValue(ImagesSpaceName.WaterTitle.bottom),
Description("獲得或設置左邊界大小")
]
public virtual int Margin_Left
 {
 get {return _marginLeft;}
set
 {
try
 {
_marginLeft = value;
}
catch(Exception exc)
 {
this.SetErrorInfo(ERRORSOURCE[0],"Margin_Left",exc.Message,ERRORINFO[0]);
throw new Exception(ERRORINFO[0]);
}
}
}
[
Bindable(true),
Category("drawing"),
DefaultValue(ImagesSpaceName.WaterTitle.bottom),
Description("獲得或設置上邊界大小")
]
public virtual int Margin_Top
 {
 get {return _marginTop;}
set
 {
try
 {
_marginTop=value;
}
catch(Exception exc)
 {
this.SetErrorInfo(ERRORSOURCE[0],"Margin_Top",exc.Message,ERRORINFO[0]);
throw new Exception(ERRORINFO[0]);
}
}
}
[
Bindable(true),
Category("drawing"),
DefaultValue(ImagesSpaceName.WaterTitle.bottom),
Description("獲得或設置右邊界的大小")
]
public virtual int Margin_Right
 {
 get {return _marginRight;}
set
 {
try
 {
_marginRight = value;
}
catch(Exception exc)
 {
this.SetErrorInfo(ERRORSOURCE[0],"Margin_Right",exc.Message,ERRORINFO[0]);
throw new Exception(ERRORINFO[0]);
}
}
}
[
Bindable(true),
Category("drawing"),
DefaultValue(ImagesSpaceName.WaterTitle.bottom),
Description("獲得或設置下邊界的大小")
]
public virtual int Margin_Bottom
 {
 get {return _marginBottom;}
set
 {
try
 {
_marginBottom = value;
}
catch(Exception exc)
 {
this.SetErrorInfo(ERRORSOURCE[0],"Margin_Bottom",exc.Message,ERRORINFO[0]);
throw new Exception(ERRORINFO[0]);
}
}
}
[
Bindable(true),
Category("drawing"),
DefaultValue(ImagesSpaceName.WaterTitle.bottom),
Description("獲得或設置坐標軸的顏色")
]
public virtual string XYColor
 {
 get {return _xyColor;}
set
 {
_xyColor = value;
try
 {
Color c = ColorTranslator.FromHtml(_xyColor);
}
catch(Exception exc)
 {
this.SetErrorInfo(ERRORSOURCE[0],"XYColor",exc.Message,ERRORINFO[1]);
throw new Exception(ERRORINFO[1]);
}
}
}
[
Bindable(true),
Category("drawing"),
DefaultValue(ImagesSpaceName.WaterTitle.bottom),
Description("獲得或設置坐標軸的大小")
]
public virtual int XYSize
 {
 get {return _xySize;}
set
 {
try
 {
_xySize = value;
}
catch(Exception exc)
 {
this.SetErrorInfo(ERRORSOURCE[0],"XYSize",exc.Message,ERRORINFO[0]);
throw new Exception(ERRORINFO[0]);
}
}
}
[
Bindable(true),
Category("drawing"),
DefaultValue(ImagesSpaceName.WaterTitle.bottom),
Description("獲得或設置坐標軸字體顏色")
]
public virtual string XYFontColor
 {
 get {return _xyFontColor;}
set
 {
_xyFontColor = value;
try
 {
Color c = ColorTranslator.FromHtml(_xyFontColor);
}
catch(Exception exc)
 {
this.SetErrorInfo(ERRORSOURCE[0],"XYFontColor",exc.Message,ERRORINFO[1]);
throw new Exception(ERRORINFO[1]);
}
}
}
[
Bindable(true),
Category("drawing"),
DefaultValue(ImagesSpaceName.WaterTitle.bottom),
Description("獲得或設置坐標軸字體大小")
]
public virtual int XYFontSize
 {
 get {return _xyFontSize;}
set
 {
try
 {
_xyFontSize = value;
}
catch(Exception exc)
 {
this.SetErrorInfo(ERRORSOURCE[0],"XYFontSize",exc.Message,ERRORINFO[0]);
throw new Exception(ERRORINFO[0]);
}
}
}
[
Bindable(true),
Category("drawing"),
DefaultValue(ImagesSpaceName.WaterTitle.bottom),
Description("獲得或設置坐標軸字體名稱")
]
public virtual string XYFontFamily
 {
 get {return _xyFontFamily;}
 set {_xyFontFamily = value;}
}
[
Bindable(true),
Category("drawing"),
DefaultValue(ImagesSpaceName.WaterTitle.bottom),
Description("獲得或設置坐標軸顯示與否")
]
public virtual bool ShowXY
 {
 get {return _showXY;}
 set {_showXY=value;}
}
[
Bindable(true),
Category("drawing"),
DefaultValue(ImagesSpaceName.WaterTitle.bottom),
Description("獲得或設置坐標軸標題顯示與否")
]
public virtual bool ShowXYTitle
 {
 get {return _showXYTitle;}
 set {_showXYTitle=value;}
}
[
Bindable(true),
Category("drawing"),
DefaultValue(ImagesSpaceName.WaterTitle.bottom),
Description("獲得或設置坐標點標題顯示與否")
]
public virtual bool ShowPointTitle
 {
 get {return _showPointTitle;}
 set {_showPointTitle=value;}
}
[
Bindable(true),
Category("drawing"),
DefaultValue(ImagesSpaceName.WaterTitle.bottom),
Description("獲得或設置圖片透明度")
]
public virtual int Alpha
 {
 get {return _alpha;}
set
 {
int iAlpha = value;
if(iAlpha<0 || iAlpha>255)
 {
this.SetErrorInfo(ERRORSOURCE[0],"PictureAlpha","",ERRORINFO[2]);
throw new Exception(ERRORINFO[2]);
}
else
_alpha = (int)(iAlpha*2.55);
}
}
[
Bindable(true),
Category("drawing"),
DefaultValue(ImagesSpaceName.WaterTitle.bottom),
Description("獲得或設置圖片透明度")
]
public virtual int BgGroundAlpha
 {
 get {return _bgGroundAlpha;}
set
 {
int iAlpha = value;
if(iAlpha<0 || iAlpha>255)
 {
this.SetErrorInfo(ERRORSOURCE[0],"BgGroundAlpha","",ERRORINFO[2]);
throw new Exception(ERRORINFO[2]);
}
else
_bgGroundAlpha = (int)(iAlpha*2.55);
}
}
 /**//// <summary>
/// 顯示X向網格
/// </summary>
public virtual bool ShowXGrid
 {
 get {return _showXGrid;}
 set {_showXGrid=value;}
}
 /**//// <summary>
/// 顯示Y向網格
/// </summary>
public virtual bool ShowYGrid
 {
 get {return _showYGrid;}
 set {_showYGrid=value;}
}
 /**//// <summary>
/// 設置或獲得網格線大小
/// </summary>
public virtual int GridLineSize
 {
 get {return _gridLineSize;}
 set {_gridLineSize=value;}
}
 /**//// <summary>
/// 設置或獲得網格線顏色
/// </summary>
public virtual string GridLineColor
 {
 get {return _gridLineColor;}
 set {_gridLineColor=value;}
}
#endregion
 設置繪圖區 void SetDrawArea()#region 設置繪圖區 void SetDrawArea()
 /**//// <summary>
/// 設置繪圖區
/// </summary>
protected virtual void SetDrawArea()
 {
this.topLeftDot = new Point(Margin_Left,Margin_Top);
this.topRightDot = new Point((int)Width-Margin_Right,Margin_Top);
this.bottomLeftDot = new Point(Margin_Left,(int)Height-Margin_Bottom);
this.bottomRightDot = new Point((int)Width-Margin_Right,(int)Height-Margin_Bottom);
}
#endregion
 繪制坐標 void DrawingRuler()#region 繪制坐標 void DrawingRuler()
 /**//// <summary>
/// 繪制坐標
/// </summary>
protected void DrawingRuler()
 {
if(ShowXY) //顯示坐標
 {
try
 {
Pen pen = new Pen(new SolidBrush(ColorTranslator.FromHtml(XYColor)),XYSize);
graphics.DrawLine(pen,bottomLeftDot,bottomRightDot);
graphics.DrawLine(pen,bottomLeftDot,topLeftDot);
graphics.DrawLine(pen,bottomRightDot.X-5,bottomRightDot.Y-5,bottomRightDot.X,bottomRightDot.Y);
graphics.DrawLine(pen,bottomRightDot.X-5,bottomRightDot.Y+5,bottomRightDot.X,bottomRightDot.Y);
graphics.DrawLine(pen,topLeftDot.X-5,topLeftDot.X+5,topLeftDot.X,topLeftDot.Y);
graphics.DrawLine(pen,topLeftDot.X+5,topLeftDot.X+5,topLeftDot.X,topLeftDot.Y);
}
catch(Exception exc)
 {
this.SetErrorInfo(ERRORSOURCE[1],"DrawingRuler",exc.Message,ERRORINFO[3]);
throw new Exception(ERRORINFO[3]);
}
}
}
#endregion
 繪制網格#region 繪制網格
 /**//// <summary>
/// 繪制網格
/// </summary>
/// <param name="arrayY">單無格數據</param>
protected void DrawingGrid(int[] arrayY)
 {
int iPos = 5; //每個單元格所占的段數
int iYlen = arrayY[0]; //Y軸上共有多少段
for(int i=0; i<arrayY.Length; i++)
 {
if(iYlen<arrayY[i]) iYlen = arrayY[i];
}
//網格線大小與顏色
Pen pen = new Pen(new SolidBrush(ColorTranslator.FromHtml(GridLineColor)),GridLineSize);
//繪制橫向網格
if(ShowXGrid)
 {
int iY = (bottomLeftDot.Y - topLeftDot.Y-10)/iYlen; //Y軸上每小段的寬度,其中10表箭頭多出的部份
for(int i=0; bottomLeftDot.Y-i>topLeftDot.Y; i+=iY*iPos)
 {
graphics.DrawLine(pen,bottomLeftDot.X,bottomLeftDot.Y-i,bottomRightDot.X,bottomRightDot.Y-i);
}
}
//繪制垂直方向網格
if(ShowYGrid)
 {
int iX = (bottomRightDot.X - bottomLeftDot.X-10)/iYlen;//X軸上每小段的寬度,其中10表箭頭多出的部份
for(int i=0; bottomLeftDot.X + i<bottomRightDot.X; i += iX*iPos)
 {
graphics.DrawLine(pen,bottomLeftDot.X+i,bottomLeftDot.Y,topLeftDot.X+i,topLeftDot.Y);
}
}
}
#endregion
}
}
|