using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;namespace HaveATry
{
public partial class Form1 : Form
{
ArrayList points;
Point currentPoint;
Pen thepen;
float penwidth;
SolidBrush thebrush;
Color thecolor; public Form1()
{
InitializeComponent();
} private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Point[] ps=(Point[])points.ToArray(typeof(Point));
if (radioButton1.Checked)
g.DrawLine(Pens.Black, ps[0], ps[ps.Length - 1]);
else if (radioButton2.Checked)
g.DrawRectangle(thepen, ps[0].X, ps[0].Y, ps[ps.Length - 1].X - ps[0].X, ps[ps.Length - 1].Y - ps[0].Y);
} private void Form1_MouseUp(object sender, MouseEventArgs e)
{
if (currentPoint.X != e.X || currentPoint.Y != e.Y)
{
currentPoint.X = e.X;
currentPoint.Y = e.Y;
points.Add(currentPoint);
this.Invalidate();
this.Update();
}
}
}
}
报错的是这一行
Point[] ps=(Point[])points.ToArray(typeof(Point));
说:未将对象引用设置到对象的实例
求问应该如何处理?
解决方案 »
- 如何判断选中的多个矩形是否构成一个新的矩形
- C# GDI+ 画虚线
- 使用DataGridViewComboBoxColumn遇到的问题
- 怎么把vs2005的website转成vs2008 webapplication?有必要转吗?
- 作为一个程序员的迷惑,软件架构的出路在那里?散尽所有的分来请大家讨论
- C#如何调用C++写的SDK
- c/s的程序直接连接远程数据库的速度很慢,如何搭建三层架构的?类似于qq,个人网上银行的这种程序是如何实现的?
- 在WEBFORM程序里,我想在DATAGRID里放一个模版列,里面放一个DROPDOWNLIST,里面的数据是从数据库里读取出来的状态值。。
- 单击button怎么弹出 contextMenuStrip
- VC#的Web XML编程 添加入xml新内容的代码疑问?
- 新手求注释,要详细,本人菜鸟
- 请大家帮我看一下这个程序哪里出了问题,感激不尽!
ps = (Point[])points.ToArray(typeof(Point));
Point currentPoint;
Pen thepen;
float penwidth;
SolidBrush thebrush;
Color thecolor;你都没有初始化值!!——即使你初始化了默认值,你根本就没有地方赋值!!
你获取一个空数据,空集合 为了什么??