写了个PDA 程序,要根据数据出一个静态曲线图.在网上找了自定义控件,编译成功后不会使用!晕~~~~~~~~~
vs.2005,建立操作流程如下:
新建-->项目-->C#-->Pocket PC 2003-->类库 然后填写代码,生成解决方案.使用操作如下:打开我的PDA程序,工程-->添加引用-->到刚才建立上面控件的目录下bin目录下-->Debug目录下CLgraph.dll选中添加,工程引用中就有了CLgraph,然后在程序里使用using CLgraph;然后编译生成解决方案.接下来怎么用啊!晕,以前没用过自定义控件.这个自定义控件应该是像Button一样是个可视控件吧!拖过来就能用了吧!如果是从那里拖?工具箱里找不到啊.还是怎么用!?自定义控件代码如下:using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;namespace CLgraph
{
class curve_line : Control
{
private int num;
private int[] a = new int[] { 1, 2 };
private int[] b = new int[] { 2, 3 };//可改变的数组
private string title;
private string w;
private string h;
private string bottomTitle;
private Color c;
Point[] p = new Point[] { new Point(10, 20), new Point(20, 30) };//画折线所用的存储数据工具!
private int average = 0;
Graphics g;
//private PictureBox pictureBox1;
private int total = 0;
public curve_line(int[] datay, int[] datax)
{
g = this.CreateGraphics();
this.a = datay;
this.b = datax;
p = (Point[])Redim(p, a.Length);//改变POINT数组大小
aver(); }
//动态修改数组模块
public static Array Redim(Array origArray, int desiredSize)
{
Type t = origArray.GetType().GetElementType();
Array newArray = Array.CreateInstance(t, desiredSize);
Array.Copy(origArray, 0, newArray, 0, Math.Min(origArray.Length, desiredSize));
return newArray;
} private void aver()
{
int j = 0, k = 0, m = 0;
for (int i = 0; i < a.Length; i++)
{
j = Math.Max(j, a[i]);
} while (k < a.Length && k < b.Length)
{
p[k] = new Point(235 - a[k], 250 - b[k]);
MessageBox.Show(a[k].ToString(), b[k].ToString());
k++; }
average = j / a.Length; }
private void DrawImage()
{
DrawXY(); //绘XY轴
DrawXLine();//绘X轴分值线
DrawYLine();//绘Y轴分值线
Drawallline();// DrawAllData();//绘出所有产品的价格线
}
#region 画出X轴与Y轴
private void DrawXY()
{ int MaxX;
int MaxY;
// Graphics g = this.CreateGraphics();
MaxX = System.Convert.ToInt32("235");
MaxY = System.Convert.ToInt32("250");
Point px1 = new Point(0, MaxY);
Point px2 = new Point(MaxX, MaxY);
//Brush backBrush = new SolidBrush(Parent.BackColor);
Pen aa = new Pen(Color.Black);
g.DrawLine(aa, px1.X, px1.Y, px2.X, px2.Y);
Point py1 = new Point(0, MaxY);
Point py2 = new Point(0, 0);
g.DrawLine(aa, py1.X, py1.Y, py2.X, py2.Y);
// g.DrawImage(
}
#endregion
#region 画出y轴上的分值线
private void DrawXLine()
{
int MaxX;
int MaxY;
// Brush backBrush = new SolidBrush(Parent.BackColor);
//Graphics g = this.CreateGraphics();
Brush backBrush = new SolidBrush(Color.Black);
MaxX = System.Convert.ToInt32("234");
MaxY = System.Convert.ToInt32("250"); for (int i = a.Length; i > 0; i--)
{
int j = average * (i - a.Length);
Point px1 = new Point(0, MaxY * i / a.Length);
Point px2 = new Point(MaxX, MaxY * i / a.Length);
g.DrawLine(new Pen(Color.Black), px1.X, px1.Y, px2.X, px2.Y);
if (!px1.Y.Equals(MaxY))
{
g.DrawString(j.ToString(), new Font("Arial", 10, FontStyle.Regular), backBrush, px1.X, px1.Y);
}
}
}
#endregion
#region 画出x轴上的分值线
private void DrawYLine()
{
int MaxX;
int MaxY; Brush backBrush = new SolidBrush(Color.Black);
MaxX = System.Convert.ToInt32("235");
MaxY = System.Convert.ToInt32("250");
for (int i = 0; i < b.Length; i++)
{
Point py1 = new Point(MaxX * i / b.Length, MaxY - 5);
Point py2 = new Point(MaxX * i / b.Length, MaxY);
g.DrawLine(new Pen(Color.Black), py1.X, py1.Y, py2.X, py2.Y);
g.DrawString(b[i].ToString(), new Font("Arial", 10, FontStyle.Regular), backBrush, py1.X + MaxX / b.Length, py2.Y); }
}
#endregion
#region 画数据
private void Drawallline()
{ g.DrawLine(new Pen(Color.Red), 0, 250, 100, 250 - 50);
g.DrawLines(new Pen(Color.Red), p);
}
#endregion
protected override void OnPaint(PaintEventArgs e)
{
DrawImage();
base.OnPaint(e);
}
}
}
vs.2005,建立操作流程如下:
新建-->项目-->C#-->Pocket PC 2003-->类库 然后填写代码,生成解决方案.使用操作如下:打开我的PDA程序,工程-->添加引用-->到刚才建立上面控件的目录下bin目录下-->Debug目录下CLgraph.dll选中添加,工程引用中就有了CLgraph,然后在程序里使用using CLgraph;然后编译生成解决方案.接下来怎么用啊!晕,以前没用过自定义控件.这个自定义控件应该是像Button一样是个可视控件吧!拖过来就能用了吧!如果是从那里拖?工具箱里找不到啊.还是怎么用!?自定义控件代码如下:using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;namespace CLgraph
{
class curve_line : Control
{
private int num;
private int[] a = new int[] { 1, 2 };
private int[] b = new int[] { 2, 3 };//可改变的数组
private string title;
private string w;
private string h;
private string bottomTitle;
private Color c;
Point[] p = new Point[] { new Point(10, 20), new Point(20, 30) };//画折线所用的存储数据工具!
private int average = 0;
Graphics g;
//private PictureBox pictureBox1;
private int total = 0;
public curve_line(int[] datay, int[] datax)
{
g = this.CreateGraphics();
this.a = datay;
this.b = datax;
p = (Point[])Redim(p, a.Length);//改变POINT数组大小
aver(); }
//动态修改数组模块
public static Array Redim(Array origArray, int desiredSize)
{
Type t = origArray.GetType().GetElementType();
Array newArray = Array.CreateInstance(t, desiredSize);
Array.Copy(origArray, 0, newArray, 0, Math.Min(origArray.Length, desiredSize));
return newArray;
} private void aver()
{
int j = 0, k = 0, m = 0;
for (int i = 0; i < a.Length; i++)
{
j = Math.Max(j, a[i]);
} while (k < a.Length && k < b.Length)
{
p[k] = new Point(235 - a[k], 250 - b[k]);
MessageBox.Show(a[k].ToString(), b[k].ToString());
k++; }
average = j / a.Length; }
private void DrawImage()
{
DrawXY(); //绘XY轴
DrawXLine();//绘X轴分值线
DrawYLine();//绘Y轴分值线
Drawallline();// DrawAllData();//绘出所有产品的价格线
}
#region 画出X轴与Y轴
private void DrawXY()
{ int MaxX;
int MaxY;
// Graphics g = this.CreateGraphics();
MaxX = System.Convert.ToInt32("235");
MaxY = System.Convert.ToInt32("250");
Point px1 = new Point(0, MaxY);
Point px2 = new Point(MaxX, MaxY);
//Brush backBrush = new SolidBrush(Parent.BackColor);
Pen aa = new Pen(Color.Black);
g.DrawLine(aa, px1.X, px1.Y, px2.X, px2.Y);
Point py1 = new Point(0, MaxY);
Point py2 = new Point(0, 0);
g.DrawLine(aa, py1.X, py1.Y, py2.X, py2.Y);
// g.DrawImage(
}
#endregion
#region 画出y轴上的分值线
private void DrawXLine()
{
int MaxX;
int MaxY;
// Brush backBrush = new SolidBrush(Parent.BackColor);
//Graphics g = this.CreateGraphics();
Brush backBrush = new SolidBrush(Color.Black);
MaxX = System.Convert.ToInt32("234");
MaxY = System.Convert.ToInt32("250"); for (int i = a.Length; i > 0; i--)
{
int j = average * (i - a.Length);
Point px1 = new Point(0, MaxY * i / a.Length);
Point px2 = new Point(MaxX, MaxY * i / a.Length);
g.DrawLine(new Pen(Color.Black), px1.X, px1.Y, px2.X, px2.Y);
if (!px1.Y.Equals(MaxY))
{
g.DrawString(j.ToString(), new Font("Arial", 10, FontStyle.Regular), backBrush, px1.X, px1.Y);
}
}
}
#endregion
#region 画出x轴上的分值线
private void DrawYLine()
{
int MaxX;
int MaxY; Brush backBrush = new SolidBrush(Color.Black);
MaxX = System.Convert.ToInt32("235");
MaxY = System.Convert.ToInt32("250");
for (int i = 0; i < b.Length; i++)
{
Point py1 = new Point(MaxX * i / b.Length, MaxY - 5);
Point py2 = new Point(MaxX * i / b.Length, MaxY);
g.DrawLine(new Pen(Color.Black), py1.X, py1.Y, py2.X, py2.Y);
g.DrawString(b[i].ToString(), new Font("Arial", 10, FontStyle.Regular), backBrush, py1.X + MaxX / b.Length, py2.Y); }
}
#endregion
#region 画数据
private void Drawallline()
{ g.DrawLine(new Pen(Color.Red), 0, 250, 100, 250 - 50);
g.DrawLines(new Pen(Color.Red), p);
}
#endregion
protected override void OnPaint(PaintEventArgs e)
{
DrawImage();
base.OnPaint(e);
}
}
}
=========================================================================
不幸~显示说没有可放置在工具箱里的控件!看样子不是可视的!
怎么用呢!!!!
如果要可以注册工具栏,好像要在类前面加上类似这样的特性
[ToolboxItem(true), DefaultBindingPropertyEx("..."),
ToolboxBitmap(typeof(curve_line), DevExpress.Utils.ControlConstants.BitmapPath + "**.bmp"),
Description("...")
]
===============================================================================
引用后双击这个类,里面是空的,啥都没有!谁帮我测试一下上面那个自定义控件,看看能用不!?谢谢了!