分享
 
 
 

用C#创建PDA应用程序的柱形图控件

王朝c#·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

VS.net本身并不提供智能设备(如PDA)应用程序的柱形图,开发智能设备应用程序时VS.net并不象Window应用程序那样提供用户自定义控件。在本文中,您将创建一个以柱形图显示的 PDAChartControl自定义控件。还将创建一个使用此 PDAChartControl自定义控件的智能设备应用程序。为了完成开发工作,您将执行这些过程:

· 创建该 PDAChartControl 自定义控件的运行时版本。

· 编译该 PDAChartControl 自定义控件的设计时版本。

· 将该控件添加到工具箱中。

· 创建一个使用该 PDAChartControl 自定义控件的智能设备应用程序。

· 在智能设备应用程序中测试该控件。

本文的重点不在于编写控件的代码,而在于如何创建设计时自定义控件以及如何将它添加到"工具箱"中。

生成自定义控件

第一步是使用智能设备类库模板创建新项目并生成控件。

创建自定义控件

1. 在"文件"菜单上指向"新建",然后单击"项目"。

2. 在"新建项目"对话框中的"项目类型"下,单击"Visual C# 项目",并在"模板"下单击"智能设备应用程序"。

3. 在"名称"框中,键入"PDAChartControlControl",然后单击"确定"。

4. 在"智能设备应用程序向导"中,单击上窗格中的"Pocket PC"和下窗格中的"类库",然后单击"确定"。

创建了一个新项目,Class1.cs 在代码编辑器中打开。

由于已经创建用于该控件的项目,接下来可以向项目中添加引用、更改代码以及编译 PDAChartControl 自定义控件的运行时版本。

编译自定义控件的运行时版本

1. 在解决方案资源管理器中,右击 Class1.cs 并单击"重命名"。

2. 重命名文件 PDAChartControlControl.cs。

注意 如果没有打开解决方案资源管理器,请单击"视图"菜单上的"解决方案资源管理器"。

用下列代码替换 PDAChartControlControl.cs 中的代码:

//*************************************

// PDAChartControlControl

using System;

using System.Collections;

using System.ComponentModel;

using System.Drawing;

using System.Data;

using System.Windows.Forms;

using System.Drawing.Drawing2D;

#if NETCFDESIGNTIME

[assembly: System.CF.Design.RuntimeAssemblyAttribute("PDAChartControl, Version=1.10.0.0, _

Culture=neutral, PublicKeyToken=null")]

namespace PDAChartControl

{

/// <summary>

/// Summary description for UserControl1.

/// </summary>

public class PDAChart : System.Windows.Forms.Control

{

public System.Windows.Forms.HScrollBar hScrollBar1;

/// <summary>

/// Required designer variable.

/// </summary>

// Delegate declaration.

// public delegate void EventHandler(string text,Color BackColor,int Height);

//

// //声明事件的委托:

// //public delegate void MyEventHandler(string text,Color BackColor,int Height);

// //定义一个公共事件成员

// public event EventHandler AddCube;

// protected virtual void OnAddCube(EventArgs e)

// {

//

// }

//

private PDAChartControl.MyGraph objGraph=new MyGraph();

private Point mBeginPoint=new Point(0,0) ;

private System.ComponentModel.Container components = null;

public PDAChart()

{

InitializeComponent();

}

public enum ChartTypeEnum { PillarChart, CakeChart ,BreakLinkChart};

#region Windows 属性定义

private bool mhScrollBarVisible=true;

#if NETCFDESIGNTIME

[System.ComponentModel.Category("PDAChart")]

[System.ComponentModel.DefaultValueAttribute(0)]

[System.ComponentModel.Description("设置/读取滚动条是否可见")]

#endif

public bool hScrollBarVisible

{

get

{

return mhScrollBarVisible;

}

set

{

mhScrollBarVisible =value;

this.Invalidate();

}

}

private ChartTypeEnum mChartType=ChartTypeEnum.PillarChart;

#if NETCFDESIGNTIME

[System.ComponentModel.Category("PDAChart")]

[System.ComponentModel.DefaultValueAttribute(0)]

[System.ComponentModel.Description("设置/读取图形类型")]

#endif

public ChartTypeEnum ChartType

{

get

{

return mChartType;

}

set

{

mChartType =value;

this.Invalidate();

}

}

private int mPicHeight=20;

#if NETCFDESIGNTIME

[System.ComponentModel.Category("PDAChart")]

[System.ComponentModel.DefaultValueAttribute(0)]

[System.ComponentModel.Description("设置/读取饼图高")]

#endif

public int PicHeight

{

get

{

return mPicHeight;

}

set

{

mPicHeight =value;

this.Invalidate();

}

}

private Font mTitleFont =new Font("Arial", 9, FontStyle.Regular);

#if NETCFDESIGNTIME

[System.ComponentModel.Category("PDAChart")]

[System.ComponentModel.Description("设置/读取文本字体")]

#endif

public Font TitleFont

{

get

{

return mTitleFont;

}

set

{

mTitleFont=value;

this.Invalidate();

}

}

private Font mTextFont =new Font("Arial", 8, FontStyle.Regular);

#if NETCFDESIGNTIME

[System.ComponentModel.Category("PDAChart")]

[System.ComponentModel.Description("设置/读取文本字体")]

#endif

public Font TextFont

{

get

{

return mTextFont;

}

set

{

mTextFont=value;

this.Invalidate();

}

}

private static DataTable mDataTable=new DataTable() ;

#if NETCFDESIGNTIME

[System.ComponentModel.Category("PDAChart")]

[System.ComponentModel.Description("设置/读取数据表")]

#endif

public DataTable dataTable

{

get

{

return mDataTable;

}

set

{

mDataTable=(DataTable)value;

this.Invalidate();

}

}

private string mShowColumnName;

#if NETCFDESIGNTIME

[System.ComponentModel.Category("PDAChart")]

[System.ComponentModel.Description("设置/读取显示列")]

#endif

public string ShowColumnName

{

get

{

return mShowColumnName;

}

set

{

mShowColumnName=value;

this.Invalidate();

}

}

private string mDataColumnName;

#if NETCFDESIGNTIME

[System.ComponentModel.Category("PDAChart")]

[System.ComponentModel.Description("设置/读取数据列")]

#endif

public string DataColumnName

{

get

{

return mDataColumnName;

}

set

{

mDataColumnName=value;

this.Invalidate();

}

}

private string mTitle="统计图";

#if NETCFDESIGNTIME

[System.ComponentModel.Category("PDAChart")]

[System.ComponentModel.DefaultValueAttribute("图表")]

[System.ComponentModel.Description("设置/读取标题")]

#endif

public string Title

{

get

{

return mTitle;

}

set

{

mTitle=value;

this.Invalidate();

}

}

private ArrayList mCubeData;

#if !NETCFDESIGNTIME

//The actual Data used to draw the line on the graph

public ICollection CubeData

{

get

{

return mCubeData;

}

set

{

mCubeData = new ArrayList(value);

Rectangle rcClient = this.ClientRectangle;

Rectangle rcGraphClient = new Rectangle(rcClient.X + 21, rcClient.Y + 5, rcClient.Width - 21, rcClient.Height - 21);

this.Invalidate(rcGraphClient);

}

}

#endif

private Color mBackColor=System.Drawing.SystemColors.ControlLight;

#if NETCFDESIGNTIME

[System.ComponentModel.Category("PDAChart")]

[System.ComponentModel.DefaultValueAttribute(0)]

[System.ComponentModel.Description("设置/读取背景颜色")]

#endif

public override Color BackColor

{

get

{

return mBackColor;

}

set

{

mBackColor =value;

this.Invalidate();

}

}

private Color mAxesXColor=System.Drawing.SystemColors.HighlightText;

#if NETCFDESIGNTIME

[System.ComponentModel.Category("PDAChart")]

[System.ComponentModel.DefaultValueAttribute(0)]

[System.ComponentModel.Description("设置/读取X轴颜色")]

#endif

public Color AxesXColor

{

get

{

return mAxesXColor;

}

set

{

mAxesXColor =value;

this.Invalidate();

}

}

private Color mAxesYColor=System.Drawing.SystemColors.Info;

#if NETCFDESIGNTIME

[System.ComponentModel.Category("PDAChart")]

[System.ComponentModel.DefaultValueAttribute(0)]

[System.ComponentModel.Description("设置/读取Y轴颜色")]

#endif

public Color AxesYColor

{

get

{

return mAxesYColor;

}

set

{

mAxesYColor =value;

this.Invalidate();

}

}

private int mLenght = 4;

#if NETCFDESIGNTIME

// These design time attributes affect appearance of this property in the property grid.

[System.ComponentModel.DefaultValueAttribute(5)]

[System.ComponentModel.Description("立体长")]

#endif

//The lower Y bound of the PDAChart

public int Lenght

{

get

{

return mLenght;

}

set

{

mLenght = value;

this.Invalidate()

[1] [2] [3] [4] [5] 下一页

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有