请大家帮忙找错!
ImageExample.rar
(33.26 KB)
程序代码:
using System; using System.Collections.Generic; using using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using namespace ImageExample { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.CancelButton = btnExit; } private void btnAddImage_Click(object sender, EventArgs e) { int i=0,j=0,k=0,high=0; string title = ""; int xs = 0, ys = 0; int xLength = 0, yLength = 0; int CONST_VALUE = 0; int minL = 0, minR = 0; int midL = 0, midR = 0; int maxL = 0, maxR = 0; int []data=new int[10000]; string []s = new string[2]; char []splitchar={','}; StreamReader sr = new StreamReader("ImageExample.txt"); title = sr.ReadLine(); s = sr.ReadLine().Split(splitchar); xs = int.Parse(s[0]); ys = int.Parse(s[1]); s = sr.ReadLine().Split(splitchar); xLength = int.Parse(s[0]); yLength = int.Parse(s[1]); CONST_VALUE = int.Parse(sr.ReadLine()); s = sr.ReadLine().Split(splitchar); minL = int.Parse(s[0]); minR = int.Parse(s[1]); s = sr.ReadLine().Split(splitchar); midL = int.Parse(s[0]); midR = int.Parse(s[1]); s = sr.ReadLine().Split(splitchar); maxL = int.Parse(s[0]); maxR = int.Parse(s[1]); while (sr.Peek()!=-1) { s= sr.ReadLine().Split(splitchar,StringSplitOptions.RemoveEmptyEntries); //j= int.Parse(s[0]); //high=int.Parse(s[1]); //就是这两句 for (k = 1; k <= j; k++) { data[i] = high; i++; } } sr.Close(); Graphics draw = this.imageLable.CreateGraphics(); Pen drawpenmin = new Pen(Color.Blue); Pen drawpenmmid = new Pen(Color.Green); Pen drawpenmax = new Pen(Color.Red); int x=0,y=0; i=0; for (x = 0; x < 100; x++) { for (y = 0; y < 100; y++) { if (data[i]+CONST_VALUE <= minR) { draw.DrawRectangle(drawpenmin, x, y, 1, 1); } else if (data[i] +CONST_VALUE<= midR) { draw.DrawRectangle(drawpenmmid, x, y, 1,1); } else { draw.DrawRectangle(drawpenmax, x, y, 1, 1); } } } minLable.Text = minL.ToString() + "---" + minR.ToString(); midLable.Text = midL.ToString() + "---" + midR.ToString(); maxLabel.Text = maxL.ToString() + "---" + maxR.ToString(); } private void btnExit_Click(object sender, EventArgs e) { Application.Exit(); } } }文本的格式如下:
程序代码:
ImageExample 0,0 100,100 0 0,50 50,100 100,250 20,25 30,75 50,150利用一个文本文件的内容在一个Label里面画图!代码中有两个句子出错,去掉程序运行正常,但不是我想要的结果!实在想不出来为什么错了,大家帮忙!
[ 本帖最后由 qq1023569223 于 2011-4-13 21:31 编辑 ]