ASP.NET教程之用C#创立PDA使用程序的柱形图控件
我感觉可以顶到50楼,出乎意料的是大家居然纷纷写出自己的博文,还被编辑做成了专题,置于首页头条。程序|创立|控件|柱形图 VS.net自己其实不供应智能设备(如PDA)使用程序的柱形图,开辟智能设备使用程序时VS.net其实不象Window使用程序那样供应用户自界说控件。在本文中,您将创立一个以柱形图显现的PDAChartControl自界说控件。还将创立一个利用此PDAChartControl自界说控件的智能设备使用程序。为了完成开辟事情,您将实行这些历程:・创立该PDAChartControl自界说控件的运转时版本。
・编译该PDAChartControl自界说控件的计划时版本。
・将该控件增加到工具箱中。
・创立一个利用该PDAChartControl自界说控件的智能设备使用程序。
・在智能设备使用程序中测试该控件。
本文的重点不在于编写控件的代码,而在于怎样创立计划时自界说控件和怎样将它增加到"工具箱"中。
天生自界说控件
第一步是利用智能设备类库模板创立新项目并天生控件。
创立自界说控件
1.在"文件"菜单上指向"新建",然后单击"项目"。
2.在"新建项目"对话框中的"项目范例"下,单击"VisualC#项目",并在"模板"下单击"智能设备使用程序"。
3.在"称号"框中,键进"PDAChartControlControl",然后单击"断定"。
4.在"智能设备使用程序导游"中,单击上窗格中的"PocketPC"和下窗格中的"类库",然后单击"断定"。
创立了一个新项目,Class1.cs在代码编纂器中翻开。
因为已创立用于该控件的项目,接上去能够向项目中增加援用、变动代码和编译PDAChartControl自界说控件的运转时版本。
<P> 编译自界说控件的运转时版本
1.在办理计划资本办理器中,右击Class1.cs并单击"重定名"。
2.重定名文件PDAChartControlControl.cs。
注重假如没有翻开办理计划资本办理器,请单击"视图"菜单上的"办理计划资本办理器"。
用以下代码交换PDAChartControlControl.cs中的代码:
//*************************************
//PDAChartControlControl
usingSystem;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Drawing;
usingSystem.Data;
usingSystem.Windows.Forms;
usingSystem.Drawing.Drawing2D;
#ifNETCFDESIGNTIME
[assembly:System.CF.Design.RuntimeAssemblyAttribute("PDAChartControl,Version=1.10.0.0,_
Culture=neutral,PublicKeyToken=null")]
namespacePDAChartControl
{
///<summary>
///SummarydescriptionforUserControl1.
///</summary>
publicclassPDAChart:System.Windows.Forms.Control
{
publicSystem.Windows.Forms.HScrollBarhScrollBar1;
///<summary>
///Requireddesignervariable.
///</summary>
//Delegatedeclaration.
//publicdelegatevoidEventHandler(stringtext,ColorBackColor,intHeight);
//
////声明事务的托付:
////publicdelegatevoidMyEventHandler(stringtext,ColorBackColor,intHeight);
////界说一个大众事务成员
//publiceventEventHandlerAddCube;
//protectedvirtualvoidOnAddCube(EventArgse)
//{
//
//}
//
privatePDAChartControl.MyGraphobjGraph=newMyGraph();
privatePointmBeginPoint=newPoint(0,0);
privateSystem.ComponentModel.Containercomponents=null;
publicPDAChart()
{
InitializeComponent();
}
publicenumChartTypeEnum{PillarChart,CakeChart,BreakLinkChart};
#regionWindows属性界说
privateboolmhScrollBarVisible=true;
#ifNETCFDESIGNTIME
#endif
publicboolhScrollBarVisible
{
get
{
returnmhScrollBarVisible;
}
set
{
mhScrollBarVisible=value;
this.Invalidate();
}
}
privateChartTypeEnummChartType=ChartTypeEnum.PillarChart;
#ifNETCFDESIGNTIME
#endif
publicChartTypeEnumChartType
{
get
{
returnmChartType;
}
set
{
mChartType=value;
this.Invalidate();
}
}
privateintmPicHeight=20;
#ifNETCFDESIGNTIME
#endif
publicintPicHeight
{
get
{
returnmPicHeight;
}
set
{
mPicHeight=value;
this.Invalidate();
}
}
privateFontmTitleFont=newFont("Arial",9,FontStyle.Regular);
#ifNETCFDESIGNTIME
#endif
publicFontTitleFont
{
get
{
returnmTitleFont;
}
set
{
mTitleFont=value;
this.Invalidate();
}
}
privateFontmTextFont=newFont("Arial",8,FontStyle.Regular);
#ifNETCFDESIGNTIME
#endif
publicFontTextFont
{
get
{
returnmTextFont;
}
set
{
mTextFont=value;
this.Invalidate();
}
}
privatestaticDataTablemDataTable=newDataTable();
#ifNETCFDESIGNTIME
#endif
publicDataTabledataTable
{
get
{
returnmDataTable;
}
set
{
mDataTable=(DataTable)value;
this.Invalidate();
}
}
privatestringmShowColumnName;
#ifNETCFDESIGNTIME
#endif
publicstringShowColumnName
{
get
{
returnmShowColumnName;
}
set
{
mShowColumnName=value;
this.Invalidate();
}
}
privatestringmDataColumnName;
#ifNETCFDESIGNTIME
#endif
publicstringDataColumnName
{
get
{
returnmDataColumnName;
}
set
{
mDataColumnName=value;
this.Invalidate();
}
}
privatestringmTitle="统计图";
#ifNETCFDESIGNTIME
#endif
publicstringTitle
{
get
{
returnmTitle;
}
set
{
mTitle=value;
this.Invalidate();
}
}
privateArrayListmCubeData;
#if!NETCFDESIGNTIME
//TheactualDatausedtodrawthelineonthegraph
publicICollectionCubeData
{
get
{
returnmCubeData;
}
set
{
mCubeData=newArrayList(value);
RectanglercClient=this.ClientRectangle;
RectanglercGraphClient=newRectangle(rcClient.X+21,rcClient.Y+5,rcClient.Width-21,rcClient.Height-21);
this.Invalidate(rcGraphClient);
}
}
#endif
privateColormBackColor=System.Drawing.SystemColors.ControlLight;
#ifNETCFDESIGNTIME
#endif
publicoverrideColorBackColor
{
get
{
returnmBackColor;
}
set
{
mBackColor=value;
this.Invalidate();
}
}
privateColormAxesXColor=System.Drawing.SystemColors.HighlightText;
#ifNETCFDESIGNTIME
#endif
publicColorAxesXColor
{
get
{
returnmAxesXColor;
}
set
{
mAxesXColor=value;
this.Invalidate();
}
}
privateColormAxesYColor=System.Drawing.SystemColors.Info;
#ifNETCFDESIGNTIME
#endif
publicColorAxesYColor
{
get
{
returnmAxesYColor;
}
set
{
mAxesYColor=value;
this.Invalidate();
}
}
privateintmLenght=4;
#ifNETCFDESIGNTIME
//Thesedesigntimeattributesaffectappearanceofthispropertyinthepropertygrid.
#endif
//ThelowerYboundofthePDAChart
publicintLenght
{
get
{
returnmLenght;
}
set
{
mLenght=value;
this.Invalidate();
}
}
privateintmMaxYValue;//图表Y轴最年夜值
privateintmMaxXValue;//图表X轴最年夜值
privateColormGridLineColor=System.Drawing.Color.Cyan;
#ifNETCFDESIGNTIME
#endif
//ThecolorofthelineofthePDAChart.
publicColorGridLineColor
{
get
{
returnmGridLineColor;
}
set
{
mGridLineColor=value;
this.Invalidate();
}
}
privateboolmShowXText=true;
#ifNETCFDESIGNTIME
//Thesedesigntimeattributesaffectappearanceofthispropertyinthepropertygrid.
#endif
//Iftrue,showstheY-ValuesontheleftofthePDAChart
publicboolIsShowXText
{
get
{
returnmShowXText;
}
set
{
mShowXText=value;
this.Invalidate();
}
}
privateboolmShowYText=true;
#ifNETCFDESIGNTIME
//Thesedesigntimeattributesaffectappearanceofthispropertyinthepropertygrid.
#endif
//Iftrue,showstheY-ValuesontheleftofthePDAChart
publicboolIsShowYText
{
get
{
returnmShowYText;
}
set
{
mShowYText=value;
this.Invalidate();
}
}
privateboolmShowXScale=true;
#ifNETCFDESIGNTIME
//Thesedesigntimeattributesaffectappearanceofthispropertyinthepropertygrid.
#endif
//Iftrue,showstheX-ValuesonthebottomofthePDAChart
publicboolIsShowXScale
{
get
{
returnmShowXScale;
}
set
{
mShowXScale=value;
this.Invalidate();
}
}
privateboolmShowYScale=true;
#ifNETCFDESIGNTIME
//Thesedesigntimeattributesaffectappearanceofthispropertyinthepropertygrid.
#endif
//Iftrue,showstheY-ValuesontheleftofthePDAChart
publicboolIsShowYScale
{
get
{
returnmShowYScale;
}
set
{
mShowYScale=value;
this.Invalidate();
}
}
privateboolmShowGrid=true;
#ifNETCFDESIGNTIME
//Thesedesigntimeattributesaffectappearanceofthispropertyinthepropertygrid.
#endif
//Iftrue,showshoriztonalgridlinesonthePDAChart.
publicboolIsShowGrid
{
get
{
returnmShowGrid;
}
set
{
mShowGrid=value;
this.Invalidate();
}
}
#endregion
///<summary>
///Cleanupanyresourcesbeingused.
///</summary>
protectedoverridevoidDispose(booldisposing)
{
if(disposing)
{
if(components!=null)
components.Dispose();
}
base.Dispose(disposing);
}
#regionComponentDesignergeneratedcode
///<summary>
///RequiredmethodforDesignersupport-donotmodify
///thecontentsofthismethodwiththeCodeEditor.
///</summary>
privatevoidInitializeComponent()
{
this.Paint+=newSystem.Windows.Forms.PaintEventHandler(this.OnPaint);
this.hScrollBar1=newSystem.Windows.Forms.HScrollBar();
this.hScrollBar1.Location=newSystem.Drawing.Point(1,100);
this.hScrollBar1.Maximum=1;
this.hScrollBar1.LargeChange=1;
this.hScrollBar1.Size=newSystem.Drawing.Size(100,16);
this.hScrollBar1.ValueChanged+=newSystem.EventHandler(this.hScrollBar1_ValueChanged);
this.Controls.Add(this.hScrollBar1);
}
#endregion
//
//privateArrayListmCudeData;
protectedoverridevoidOnResize(EventArgse)
{
//this.Refresh();
}
GraphicsmGraphics;
PenmBlackPen=newPen(Color.Black);
//偏向
intTopHeightWarp=16;//顶偏向(文本高)
intLeftWidthWarp=0;//左偏向(最年夜数据文本宽)
intUnderHeightWarp=10;//底偏向(底文本高)
intBetweenLineHeight=10;//程度线的高
intLineCount=10;//程度线数
////ThisPaintfunctionusesroutinescommontobothplatforms.
intClientHeight;
intmWidth;
intYHeight;
RectanglercClient;
System.Drawing.RegionRegion1;
publicvoidOnPaint(objectsender,System.Windows.Forms.PaintEventArgse)
{
//base.Paint(null,e);
mGraphics=e.Graphics;
//读取数据
this.rcClient=this.ClientRectangle;
Region1=newRegion(this.rcClient);
Region1=Region1.Clone();
ClientHeight=rcClient.Height;
objGraph.mGraphics=e.Graphics;//mGraphics.MeasureString//
//盘算最年夜的x轴、y轴坐标
CountMaxScaleXScaleY();
UnderHeightWarp=(int)objGraph.mGraphics.MeasureString("文本",this.mTextFont).Height+5;
UnderHeightWarp+=this.hScrollBar1.Height;
//作图的局限区(入手下手点、长、宽、高)
mBeginPoint.X=this.ClientRectangle.X+LeftWidthWarp;
mBeginPoint.Y=this.ClientRectangle.Y+rcClient.Height-UnderHeightWarp;
//写题目
DrawTitle(rcClient);
intWidth=rcClient.Width-this.mLenght-LeftWidthWarp;
mWidth=Width;
intHeight=rcClient.Height-this.mLenght-TopHeightWarp-UnderHeightWarp;
this.YHeight=Height;
intLenght=this.mLenght;
//设置活动条
//this.hScrollBar1.Location=newSystem.Drawing.Point(0,rcClient.Y+rcClient.Height);
InitPage();
if(this.hScrollBarVisible)
{
this.hScrollBar1.Left=0;
this.hScrollBar1.Top=rcClient.Height-this.hScrollBar1.Height;
this.hScrollBar1.Maximum=this.PageCount-1;
if(rcClient.Width<246)
this.hScrollBar1.Width=rcClient.Width;
else
this.hScrollBar1.Width=246;
}
else
{
this.hScrollBar1.Left=0;
this.hScrollBar1.Top=0;
}
//今后分离绘图
if(this.mMaxYValue>10)
{
//程度收集线
this.BetweenLineHeight=(int)objGraph.mGraphics.MeasureString("文本",this.mTextFont).Height;
this.LineCount=Height/BetweenLineHeight;
}
else
{
this.BetweenLineHeight=Height/10;
//线数应当是能整
this.LineCount=10;
}
//画与它父不异背景色彩的地区,以埋没角边
ColorParentBackColor=Color.Brown;
objGraph.DrawRectangle(ParentBackColor,newPoint(0,0),rcClient.Width,rcClient.Height);
e.Graphics.DrawRectangle(newPen(ParentBackColor),rcClient);
objGraph.DrawPDAChart(this.mGridLineColor,this.mAxesXColor,this.mAxesYColor,_
this.mBackColor,mBeginPoint,Lenght,Width,Height,this.mShowXScale,this.mShowYScale);
//画线和左文本(外部左下点)
Pointp=mBeginPoint;
p.X+=this.mLenght;
p.Y-=this.mLenght;
DrawGridLineAndTexts(p,Width);
//mBeginPoint
//画矩形与写文本
//CreateCubes(mBeginPoint,Width,rcClient.Height);
//mBeginPoint.X+=10;
CreatePageCubes(mBeginPoint,Width,ClientHeight);
DrawTitle(rcClient);
}
}
//以左下坐标p,色彩color,长Lenght,宽Width,高Height,x轴文本textX,画平面图
publicvoidAddOneCube(stringtextX,Pointp,Colorcolor,intLenght,intWidth,intHeight)
{
try
{
objGraph.DrawCube(color,p,Lenght,Width,Height);
//文本
inttxtWidth=(int)objGraph.mGraphics.MeasureString(textX,mTextFont).Width;
inttxtHeight=(int)objGraph.mGraphics.MeasureString(textX,mTextFont).Height;
intx=(p.X+Width/2)-txtWidth/2;
inty=p.Y+txtHeight/2;
this.objGraph.DrawText(textX,Color.Black,this.mTextFont,x,y-5);
}
catch(Exceptionex)
{
stringstr=ex.Message;
}}
//一页立方体图形个数
intOnePageCubeCount=10;
intCurrentPage=0;//以后页
intPageCount=0;//几页
//程度轴的绝对值
intXScale;
//Y轴的绝对值
doubleYScale=0.2;
Color[]color={Color.Red,Color.Blue,Color.Green,Color.Yellow,Color.YellowGreen,Color.Magenta,_
Color.Cyan,Color.Coral,Color.SlateGray,Color.Pink,Color.Crimson,Color.DodgerBlue,Color.Chartreuse};
//盘算页
privatevoidInitPage()
{
if(this.OnePageCubeCount==0)return;
if(mDataTable.Rows.Count<OnePageCubeCount)
this.OnePageCubeCount=mDataTable.Rows.Count;
if(this.OnePageCubeCount==0)return;
PageCount=mDataTable.Rows.Count/this.OnePageCubeCount;
//程度轴的绝对值
XScale=Width/this.OnePageCubeCount;
//Y轴的绝对值
if(this.mMaxYValue<=0)return;
{
if(this.mMaxYValue==0)return;
this.YScale=double.Parse(this.YHeight.ToString())/double.Parse(this.mMaxYValue.ToString());//System.Math.
//this.YScale=double.Parse(this.YScale.ToString())/double.Parse(this.LineCount.ToString());
}
//this.YScale=double.Parse(System.Convert.ToString(1))/double.Parse(this.mMaxYValue.ToString());//System.Math.
}
privatevoidhScrollBar1_ValueChanged(objectsender,System.EventArgse)
{
//OnPaint(objectsender,System.Windows.Forms.PaintEventArgse)
//清画出的图
this.CurrentPage=hScrollBar1.Value;
//if(mGraphics.Clip==null)
//{
mGraphics=this.CreateGraphics();
this.objGraph.mGraphics=mGraphics;
//}
//mGraphics.Clip=this.Region1;
//画矩形与写文本,最多一屏
//mGraphics.Clear(this.mBackColor);
//mGraphics.ResetClip();
//CreatePageCubes(mBeginPoint,Width,ClientHeight);
System.Windows.Forms.PaintEventArgse1=newPaintEventArgs(mGraphics,this.rcClient);
OnPaint(null,e1);
}
publicvoidNextPage()
{
this.objGraph.mGraphics=this.CreateGraphics();
this.CurrentPage++;
Bitmapbm=newBitmap(10,10);
Graphicsg=Graphics.FromImage(bm);
if(this.CurrentPage>this.PageCount)
this.CurrentPage--;
//画矩形与写文本,最多一屏
//mGraphics.Clear(Color.Red);
//mGraphics.ResetClip();
CreatePageCubes(mBeginPoint,Width,ClientHeight);
}
//在左下极点,宽Width,高Height创建立方体
privatevoidCreatePageCubes(PointBeginP,intWidth,intHeight)
{
if(mDataTable.Rows.Count==0)return;
intBetween=10;
switch(this.OnePageCubeCount)
{
case1:
Between=mWidth/2;
break;
case2:
Between=mWidth/3;
break;
case3:
Between=mWidth/4;
break;
case4:
Between=mWidth/5;
break;
case5:
Between=mWidth/6;
break;
case6:
Between=mWidth/7;
break;
case7:
Between=mWidth/8-1;
break;
case8:
Between=mWidth/9-2;
break;
case9:
Between=mWidth/9-5;
break;
case10:
Between=mWidth/10-5;
break;
}
intRowIndex=this.OnePageCubeCount*this.CurrentPage;
Pointp=BeginP;//dr.
p.X-=8;
for(inti=0;i<this.OnePageCubeCount;i++)
{
//p.X=this.XScale*(i+1)+10;
p.X+=Between+this.mLenght;
doubleCubeHeight=this.YScale*System.Convert.ToInt32(mDataTable.Rows);
//if((p.X>=0)&&(p.X<=Width)&&(p.Y>=0)&&(p.Y<=Height))
//{
stringtext=mDataTable.Rows.ToString();
stringData=mDataTable.Rows.ToString();
intColorIndex=RowIndex;
if(ColorIndex>=color.Length)
ColorIndex=color.Length-1;
if(this.mShowXText==false)text="";
AddOneCube(text,p,color,this.mLenght,this.mLenght+4,System.Convert.ToInt32(CubeHeight));
//}
RowIndex++;
}
}
//在左下极点,宽Width,高Height创建立方体
privatevoidCreateCubes(PointBeginP,intWidth,intHeight)
{
if(mDataTable.Rows.Count==0)return;
//程度轴的绝对值
intXScale=Width/mDataTable.Rows.Count;
//Y轴的绝对值
if(this.mMaxYValue<=0)return;
intYScale=Height/(this.mMaxYValue*this.LineCount);
intRowIndex=0;
Color[]color={Color.Red,Color.Blue,Color.Green,Color.Yellow,Color.YellowGreen,Color.Magenta,_
Color.Cyan,Color.Coral,Color.SlateGray,Color.Pink,Color.Crimson,Color.DodgerBlue,Color.Chartreuse};
foreach(DataRowdrinmDataTable.Rows)
{
RowIndex+=1;
Pointp=BeginP;//dr.
p.X=XScale*RowIndex+10;
intCubeHeight=YScale*System.Convert.ToInt32(dr);
if((p.X>=0)&&(p.X<=Width)&&(p.Y>=0)&&(p.Y<=Height))
{
stringtext=dr.ToString();
stringData=dr.ToString();
intColorIndex=RowIndex;
if(ColorIndex>=color.Length)
ColorIndex=color.Length-1;
if(this.mShowXText==false)text="";
AddOneCube(text,p,color,this.mLenght,this.mLenght+5,CubeHeight);
//objGraph.DrawCube(color,p,this.mLenght,Width,Height);
}
}
}
//盘算最年夜的x、y轴坐标,右边文本宽,最小的线高
privatevoidCountMaxScaleXScaleY()
{
if(mDataTable.Rows.Count==0)return;
this.mMaxXValue=mDataTable.Rows.Count;
this.mMaxYValue=0;
//this.l.
foreach(DataRowdrinmDataTable.Rows)
{
intCubeHeight=System.Convert.ToInt32(dr);
if(mMaxYValue<CubeHeight)
{
mMaxYValue=CubeHeight;
}
intTextWidth=(int)objGraph.mGraphics.MeasureString(System.Convert.ToDouble(dr)._
ToString(),this.mTextFont).Width+10;
if(LeftWidthWarp<TextWidth)
{
LeftWidthWarp=TextWidth;
}
}
//LeftWidthWarp+=10;
}
//在顶部中央地位写题目
privatevoidDrawTitle(RectanglercClient)
{
intWidth=(int)objGraph.mGraphics.MeasureString(this.mTitle,mTitleFont).Width;
intHeight=(int)objGraph.mGraphics.MeasureString(this.mTitle,mTitleFont).Height;
this.TopHeightWarp=Height;
intx=rcClient.Width/2-Width/2;
inty=rcClient.Y+Height/2-5;
this.objGraph.DrawText(this.mTitle,Color.Blue,mTitleFont,x,y);
}
//画一切程度收集线
//p:肇端点;Width:线宽;BetweenHeight:二线之间高,Count:线数
//privatevoidDrawGridLineAndTexts(Pointp,intWidth)
//{
//for(inti=0;i<this.LineCount;i++)
//{
//DrawGridLineAndText(p,p,Width,Lenght);
//p.Y-=BetweenHeight;
//}
//}
//由极点与长、宽、高画色彩为color,背景致为的BackColor图表(3D)
privatevoidDrawGridLineAndTexts(Pointp,intWidth)
{//是不是显现收集程度线
if(this.mShowGrid)
{
this.objGraph.DrawGridLines(this.mGridLineColor,p,Width-1,this.mLenght,this.BetweenLineHeight,this.LineCount);
}
//是不是显现左文本
if(this.mShowYText)
{
Pointp1=p;
//p1.X-=this.mLenght;
p1.Y+=Lenght;
doublea1=double.Parse(System.Convert.ToString(this.LineCount-1));
doublea2=double.Parse(this.mMaxYValue.ToString());
doublea=System.Math.Round(a2/a1,1);
for(inti=0;i<this.LineCount;i++)
{
stringText=System.Convert.ToString(a*(i+1));
inttxtWidth=(int)objGraph.mGraphics.MeasureString(Text,this.mTextFont).Width;
p1.X=p.X-txtWidth-this.mLenght;;
p1.Y-=this.BetweenLineHeight;
this.objGraph.DrawText(Text,Color.Black,this.mTextFont,p1.X,p1.Y);
}
}
}
//求数据列的和
privatedoubleSumColumn(DataTabledt,stringColumnName)
{
doubleSum=0.0;
foreach(DataRowdrindt.Rows)
{
Sum+=System.Convert.ToDouble(dr);
}
returnSum;
}
}
#region
publicclassMyGraph
{
//收集程度线中二线之间的高
//intBetweenLineHeight=20;
//最年夜MaxYCount:线数
//intMaximumY=10;
//intLenght=5;
//intWidth=200;
//intHeight=300;
//boolIsShowGrid=true;
publicGraphicsmGraphics;
//背景致
//publicColorBackColor=System.Drawing.SystemColors.Control;
////X轴色彩
//publicColorAxesXColor=System.Drawing.SystemColors.HighlightText;
////Y轴色彩
//publicColorAxesYColor=System.Drawing.SystemColors.Info;
//玄色笔
privatePenmBlackPen=newSystem.Drawing.Pen(Color.FromArgb(0,0,0));
//网格线笔
privatePenmGridPen=newSystem.Drawing.Pen(Color.FromArgb(127,127,127));
//ColorBackColor=System.Drawing.Color.FromArgb(((System.Byte)(224)),((System.Byte)(224)),((System.Byte)(224)));
publicMyGraph()
{
//mGraphics=this.CreateGraphics();//
//TODO:在此处增加机关函数逻辑
//
}
//由左下极点与宽、高画色彩为color的平行四边形
publicvoidDrawRectangle3DTop(Colorcolor,PointLeftUnderPoint,intWidth,intHeight)
{
try
{
//盘算左上极点
Pointp1=newPoint();
p1.X=LeftUnderPoint.X+Height;
p1.Y=LeftUnderPoint.Y-Height;
//盘算右上极点
Pointp2=newPoint();
p2.X=LeftUnderPoint.X+Width+Height;
p2.Y=LeftUnderPoint.Y-Height;
//盘算右下极点
Pointp3=newPoint();
p3.X=LeftUnderPoint.X+Width;
p3.Y=LeftUnderPoint.Y;
Point[]curvePoints=
{
LeftUnderPoint,
p1,
p2,
p3
};
//Definefillmode.
//FillModenewFillMode=FillMode.Winding;
//Fillpolygontoscreen.
//Createsolidbrush.
SolidBrushBrush=newSolidBrush(color);
mGraphics.FillPolygon(Brush,curvePoints);
//mGraphics.FillPolygon(Brush,curvePoints,newFillMode);
//画边框
mGraphics.DrawPolygon(this.mBlackPen,curvePoints);
}
catch(Exceptionex)
{
stringstr=ex.Message;
}
}
//由左下极点与宽、高画色彩为color的同等四边形
publicvoidDrawRectangle3DRight(Colorcolor,PointLeftUnderPoint,intWidth,intHeight)
{
try
{
//Createsolidbrush.
SolidBrushBrush=newSolidBrush(color);
//盘算左上极点
Pointp1=newPoint();
p1.X=LeftUnderPoint.X;
p1.Y=LeftUnderPoint.Y-Height;
//盘算右上极点
Pointp2=newPoint();
p2.X=p1.X+Width;
p2.Y=p1.Y-Width;
//盘算右下极点
Pointp3=newPoint();
p3.X=LeftUnderPoint.X+Width;
p3.Y=LeftUnderPoint.Y-Width;
Point[]curvePoints=
{
LeftUnderPoint,
p1,
p2,
p3
};
//Definefillmode.
//FillModenewFillMode=FillMode.Winding;
//Fillpolygontoscreen.
mGraphics.FillPolygon(Brush,curvePoints);
//画边框
mGraphics.DrawPolygon(this.mBlackPen,curvePoints);
//mGraphics.FillPolygon(Brush,curvePoints,newFillMode);
}
catch(Exceptionex)
{
stringstr=ex.Message;
}
}
//由左上角极点与宽、高画色彩为color的平行四边形
publicvoidDrawRectangle(Colorcolor,PointP,intWidth,intHeight)
{
RectangleRectangle1=newRectangle(P.X,P.Y,Width,Height);
//Createsolidbrush.
SolidBrushBrush=newSolidBrush(color);
//Fillpolygontoscreen.
mGraphics.FillRectangle(Brush,Rectangle1);
//画边框
mGraphics.DrawRectangle(this.mBlackPen,Rectangle1);
}
//由左下极点与长、宽、高画色彩为color的立方图形(3D)
publicvoidDrawCube(Colorcolor,PointLeftUnderPoint,intLenght,intWidth,intHeight)
{
//Createsolidbrush.
SolidBrushBrush=newSolidBrush(color);
PointLeftTopPoint=LeftUnderPoint;
LeftTopPoint.Y-=Height;
DrawRectangle3DTop(color,LeftTopPoint,Width,Lenght);
DrawRectangle(color,LeftTopPoint,Width,Height);
PointRightP=LeftUnderPoint;
RightP.X+=Width;
DrawRectangle3DRight(Color.Black,RightP,Lenght,Height);
}
//画X轴
publicvoidDrawAxesX(Colorcolor,Pointp,intWidth,intHeight)
{
DrawRectangle3DTop(color,p,Width,Height);
}
//画Y轴
publicvoidDrawAxesY(Colorcolor,Pointp,intWidth,intHeight)
{
DrawRectangle3DRight(color,p,Width,Height);
}
//由极点与长、宽、高画色彩为color,背景致为的BackColor图表(3D)
publicvoidDrawPDAChart(ColorGridLineColor,ColorAxesXColor,ColorAxesYColor,_
ColorBackColor,Pointp,intLenght,intWidth,intHeight,boolIsShowAxesX,boolIsShowAxesY)
{
if(IsShowAxesX)
{
//画X轴
DrawAxesX(AxesXColor,p,Width,Lenght);
}
if(IsShowAxesY)
{
//画Y轴
DrawAxesY(AxesYColor,p,Lenght,Height);
}
////绘图形区
PointpRectangle=p;
pRectangle.X+=Lenght;
pRectangle.Y-=Lenght;
pRectangle.Y-=Height;
DrawRectangle(BackColor,pRectangle,Width,Height);
}
//画一条程度收集线与对应的折线
publicvoidDrawGridLine(ColorGridLineColor,Pointp,intWidth,intLenght)
{
//DrawtheYscale;
PointEndP=p;
EndP.X+=Width;
Penpen=newPen(GridLineColor);
//this.mGraphics.DrawLine(pen,p,EndP);
//程度线
this.mGraphics.DrawLine(pen,p.X,p.Y,EndP.X,EndP.Y);
//左折线
this.mGraphics.DrawLine(pen,p.X,p.Y,EndP.X-Lenght,EndP.Y+Lenght);
}
//画一切程度收集线
//p:肇端点;Width:线宽;BetweenHeight:二线之间高,Count:线数
publicvoidDrawGridLines(ColorGridLineColor,Pointp,intWidth,intLenght,intBetweenHeight,intCount)
{
Penpen=newPen(GridLineColor);
for(inti=0;i<Count;i++)
{
//DrawGridLine(GridLineColor,p,Width,Lenght);
//程度线
this.mGraphics.DrawLine(pen,p.X,p.Y,p.X+Width,p.Y);
//左折线
this.mGraphics.DrawLine(pen,p.X-Lenght+1,p.Y+Lenght,p.X,p.Y);
p.Y-=BetweenHeight;
}
}
//在地位(x,y)处以色彩color、字体font写文本text
publicvoidDrawText(stringtext,Colorcolor,Fontfont,intx,inty)
{
//Createsolidbrush.
SolidBrushBrush=newSolidBrush(color);
this.mGraphics.DrawString(text,font,Brush,x,y);
}
//由点p(矩形左上角点),宽pieWidth,高pieHeight,色彩color画馅饼图
publicvoidDrawCake(Colorcolor,Pointp,intpieWidth,intpieLenght,intpieHeight)
{
PenPenBlack=newPen(Color.Black);
//玄色最上面的椭A
Rectanglerc1=newRectangle(p.X,p.Y+pieHeight,pieWidth,pieLenght);
this.mGraphics.DrawEllipse(PenBlack,rc1);
SolidBrushobjBrush=newSolidBrush(color);
for(inti=0;i<pieHeight;i++)
{
this.mGraphics.FillEllipse(objBrush,p.X,p.Y+i,pieWidth,pieLenght);
}
//玄色最下面的椭A
Rectanglerc=newRectangle(p.X,p.Y,pieWidth,pieLenght);
this.mGraphics.DrawEllipse(PenBlack,rc);
this.mGraphics.DrawLine(PenBlack,p.X,p.Y+pieLenght/2,p.X,p.Y+pieHeight+pieLenght/2);
this.mGraphics.DrawLine(PenBlack,p.X+pieWidth,p.Y+pieLenght/2,p.X+pieWidth,p.Y+pieHeight+pieLenght/2);
}
//求隋圆恣意一点x坐标的绝对点
//角angle,中央点oPoint,a,长半轴,b,短半轴
publicdoubleGetEllipsePX(doubleangle,inta,intb)
{
//角
doubleradians=angle*(Math.PI/180);
doublepx=a*System.Math.Cos(radians);
returnpx;
}
//求隋圆恣意一点y坐标的绝对点
//角angle,中央点oPoint,a,长半轴,b,短半轴
publicdoubleGetEllipsePY(doubleangle,inta,intb)
{
//角
doubleradians=angle*(Math.PI/180);
doublepy=b*System.Math.Sin(radians);
returnpy;
}
//画线椭圆线
//角angle,中央点oPoint,a,长半轴,b,短半轴
publicvoidDrawEllipseLine(doubleangle,PointoPoint,inta,intb)
{
intpx=System.Convert.ToInt32(GetEllipsePX(angle,a,b))+oPoint.X;
intpy=System.Convert.ToInt32(GetEllipsePY(angle,a,b))+oPoint.Y;
PenPenBlack=newPen(Color.Black);
this.mGraphics.DrawLine(PenBlack,oPoint.X,oPoint.Y,px,py);
//e.Graphics.DrawLine(PenBlack,oPoint.X,oPoint.Y,oPoint.X+b,oPoint.Y);
}
//取扇形的点集(逆时针)
//角angle,已画过的角FinishAngle,中央点oPoint,长半轴a,短半轴b
publicArrayListGetPicPoints(doubleangle,doubleFinishAngle,PointoPoint,inta,intb)
{
//PointcurvePoints=newArray();
//以步长为1求扇形弧线的坐标点
ArrayListpList=newArrayList();
pList.Add(oPoint);
//pList.Add(ArcStartPoint);
for(inti=0;i<System.Convert.ToInt32(angle);i++)
{
intpx=System.Convert.ToInt32(GetEllipsePX(i+FinishAngle,a,b))+oPoint.X;
intpy=System.Convert.ToInt32(GetEllipsePY(i+FinishAngle,a,b))+oPoint.Y;
pList.Add(newPoint(px,py));
//curvePoints.SetValue(
}
returnpList;
}
//画扇形(逆时针)
//角度angle,已画过的角FinishAngle,中央点oPoint,长半轴a,短半轴b
publicvoidDrawPDAPic(Colorcolor,stringtext,doubleangle,doubleFinishAngle,PointoPoint,inta,intb)
{
//Createsolidbrush.
SolidBrushBrush=newSolidBrush(color);
ArrayListpList=GetPicPoints(angle,FinishAngle,oPoint,a,b);
Point[]curvePoints=newPoint;
for(inti=0;i<pList.Count;i++)
curvePoints=(Point)pList;
mGraphics.FillPolygon(Brush,curvePoints);
//画边框
mGraphics.DrawPolygon(this.mBlackPen,curvePoints);
//DrawText(text,Color.Black,this.
}
}
#endregion
3.在办理计划资本办理器中,右击"援用",然后单击"增加援用"。
4.在"增加援用"对话框中的".NET"选项卡上,单击"System.Drawing",然后单击"选择"。
"System.Drawing"会呈现在"选定的组件"下。
5.对"System.Windows.Forms"反复步骤4并单击"断定"。
"System.Drawing"和"System.Windows.Forms"城市呈现在办理计划资本办理器的"援用"下。
6.在"天生"菜单上,单击"天生办理计划"。
将天生控件PDAChartControlControl.dll的运转时版本并将其放在目次Projects_DirectoryPDAChartControlControinDebug中。
7.在"文件"菜单中,单击"封闭办理计划"。
因为天生了控件的运转时版本,接上去能够为计划器撑持天生计划时版本。
天生自界说控件的计划时版本
1.翻开VisualStudio.NET命令提醒。
注重要翻开VisualStudio.NET命令提醒,请单击"入手下手",再顺次指向"程序"、"MicrosoftVisualStudio.NET2003"和"VisualStudio.NET工具",然后单击"VisualStudio.NET命令提醒"。
2.切换到包括PDAChartControlControl.cs的目次。
3.在命令提醒处键进以下内容:
csc/noconfig/define:NETCFDESIGNTIME/target:library/out:design.PDAChartControlControl.dllPDAChartControlControl.cs/r:"C:ProgramFilesMicrosoftVisualStudio.NET2003CompactFrameworkSDKv1.0.5000WindowsCEDesignerSystem.CF.Design.dll"/r:"C:ProgramFilesMicrosoftVisualStudio.NET2003CompactFrameworkSDKv1.0.5000WindowsCEDesignerSystem.CF.Windows.Forms.dll"/r:"C:ProgramFilesMicrosoftVisualStudio.NET2003CompactFrameworkSDKv1.0.5000WindowsCEDesignerSystem.CF.Drawing.dll"/r:System.Windows.Forms.dll/r:System.Drawing.dll/r:System.dll/r:System.XML.dll/r:System.Web.Services.dll/r:System.Data.dll/nowarn:1595
这将天生自界说控件的计划时版本。文件design.PDAChartControlControl.dll安排在以后目次中。
将自界说控件增加到工具箱
因为编译了控件的运转时和计划时版本,接上去能够将该控件增加到"工具箱",并在智能设备使用程序中利用它了。
将自界说控件增加到"工具箱"的步骤:
1.将文件design.PDAChartControlControl.dll复制到目次ProgramFilesMicrosoftVisualStudio.NET2003CompactFrameworkSDKv1.0.5000WindowsCEDesigner中。
2.将文件PDAChartControlControl.dll复制到目次ProgramFilesMicrosoftVisualStudio.NET2003CompactFrameworkSDKv1.0.5000WindowsCE中。
3.在"视图"菜单上单击"工具箱"。
4.右击"惯例",然后单击"显现一切选项卡"。
5.单击"设备控件"以显现设备上可用控件的完全列表。
6.右击"指针",然后单击"增加/移除项"。
7.在"自界说工具箱"对话框的".NETFramework组件"选项卡上,单击"扫瞄"。
8.选择"design.PDAChartControlControl.dll"并单击"翻开",将"PDAChartControl"控件增加到"自界说工具箱"对话框中的组件列表。
9.在.NETFramework组件列表当选择"PDAChartControl"控件,然后单击"断定"。
"PDAChartControl"控件即被增加到"工具箱"中。
测试自界说控件
因为自界说控件呈现在"工具箱"中,接上去可使用Windows窗体计划器将它拖到窗体上。
将自界说控件增加到窗体
1.在"文件"菜单上指向"新建",然后单击"项目"。
2.在"新建项目"对话框中的"项目范例"下,单击"VisualC#项目",并在"模板"下单击"智能设备使用程序"。
3.在"称号"框中,键进"PDAChartControlControlTest",然后单击"断定"。
4.在"智能设备使用程序导游"中,单击上窗格中的"PocketPC"和下窗格中的"Windows使用程序",然后单击"断定"。
创立了新项目,Form1.cs在计划器中翻开。
5.从工具箱将"PDAChartControl"控件拖到窗体上。
自界说控件即被增加到窗体上,指向PDAChartControlControl的援用则被增加到项目中。
注重假如工具箱不成见,则在"检察"菜单上,单击"工具箱"。
<P> 主动天生的代码以下:
PDAChartControl.PDAChartMyGraph=newPDAChartControl.PDAChart();
this.pdaChart1.AxesXColor=System.Drawing.SystemColors.HighlightText;
this.pdaChart1.AxesYColor=System.Drawing.SystemColors.Info;
this.pdaChart1.BackColor=System.Drawing.SystemColors.ControlLight;
this.pdaChart1.ChartType=PDAChartControl.PDAChart.ChartTypeEnum.CakeChart;
this.pdaChart1.DataColumnName="DataID";
this.pdaChart1.GridLineColor=System.Drawing.Color.Cyan;
this.pdaChart1.hScrollBarVisible=true;
this.pdaChart1.IsShowGrid=true;
this.pdaChart1.Location=newSystem.Drawing.Point(8,24);
this.pdaChart1.PicHeight=20;
this.pdaChart1.ShowColumnName="ShowID";
this.pdaChart1.Size=newSystem.Drawing.Size(224,240);
this.pdaChart1.Text="pdaChart1";
this.pdaChart1.TextFont=newSystem.Drawing.Font("Arial",8F,System.Drawing.FontStyle.Regular);
this.pdaChart1.Title="统计图";
this.pdaChart1.TitleFont=newSystem.Drawing.Font("Arial",9F,System.Drawing.FontStyle.Regular);
this.pdaChart1.hScrollBar1.Visible=false;
this.Controls.Add(this.pdaChart1);
6.天生测试数据
//测试数据
this.pdaChart1.dataTable=CreateQueryTable();
this.pdaChart1.DataColumnName="DataID";
this.pdaChart1.ShowColumnName="ShowID";
//创建查询明细表
privateDataTableCreateQueryTable()
{
DataTabledt=newDataTable("query");
dt.Columns.Add("DataID");
dt.Columns.Add("ShowID");
for(inti=0;i<10;i++)
{
DataRowdr=dt.NewRow();
dr["DataID"]=(i+1)*10;
dr["ShowID"]=(i+1).ToString();
dt.Rows.Add(dr);
}
returndt;
}
7.在"设备"工具栏的"部署设备"框中,选择要用作方针的设备。
8.在"调试"菜单上单击"入手下手实行(不调试)"。
编译该使用程序并将其部署到方针设备上(与运转时所需的任何其他库一同),然后在设备上启动该使用程序。
实行了局以下:
可怜的程序员,还是逃不出移植的命运! ASP.NET可以无缝地与WYSIWYGHTML编辑器和其他编程工具(包括MicrosoftVisualStudio.NET)一起工作。这不仅使得Web开发更加方便,而且还能提供这些工具必须提供的所有优点,包括开发人员可以用来将服务器控件拖放到Web页的GUI和完全集成的调试支持。微软为ASP.net设计了这样一些策略:易于写出结构清晰的代码、代码易于重用和共享、可用编译类语言编写等等,目的是让程序员更容易开发出Web应用,满足计算向Web转移的战略需要。 ASP(ActiveServerPages)是Microsfot公司1996年11月推出的WEB应用程序开发技术,它既不是一种程序语言,也不是一种开发工具,而是一种技术框架,不须使用微软的产品就能编写它的代码。 ASP.net1.1和2.0在程序上的语法也有很大不同,现在2.0属于新出来的,不知道半年后会不会有3.0(说笑一下)。Windows2003系统自动支持ASP和ASP.net环境,不用安装任何程序。Asp.net属于编译语言。ASP的最大不同(ASP属于解释语言)。 微软又推出ASP.NET。这不是ASP的简单升级,而是全新一代的动态网页实现系统,用于一台WEB服务器建立强大的应用程序。是微软发展的新体系结构.NET的一部分,是ASP和.NET技术的结合。 由于JSP/Servlet都是基于Java的,所以它们也有Java语言的最大优点——平台无关性,也就是所谓的“一次编写,随处运行(WORA–WriteOnce,RunAnywhere)”。除了这个优点,JSP/Servlet的效率以及安全性也是相当惊人的。 比如封装性、继承性、多态性等等,这就解决了刚才谈到的ASP的那些弱点。封装性使得代码逻辑清晰,易于管理,并且应用到ASP.Net上就可以使业务逻辑和Html页面分离,这样无论页面原型如何改变。 主流网站开发语言之ASP:ASP是微软(Microsoft)所开发的一种后台脚本语言,它的语法和VisualBASIC类似,可以像SSI(ServerSideInclude)那样把后台脚本代码内嵌到HTML页面中。虽然ASP简单易用,但是它自身存在着许多缺陷,最重要的就是安全性问题。 ASP.NET:ASP.net是Microsoft.net的一部分,作为战略产品,不仅仅是ActiveServerPage(ASP)的下一个版本;它还提供了一个统一的Web开发模型,其中包括开发人员生成企业级Web应用程序所需的各种服务。ASP.NET的语法在很大程度上与ASP兼容,同时它还提供一种新的编程模型和结构,可生成伸缩性和稳定性更好的应用程序,并提供更好的安全保护。
页:
[1]