c# Windows Form遇到问题

schnappie 2010-07-26 10:57:53
各位前辈,我想编写如图这个程序



目的是寻找一个txt文档,读取里面的x,y,z值,然后在form2里画出关于z的图。现在我能写的是可以读取x,y,z. RichtextBox上也能显示出txt文档里的内容。但是把x,y,z的值调到Form2里运用,我不会。请那位好心的大大写下详细的代码,谢谢
我写的代码如下


Form1.cs


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;


namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()

{
InitializeComponent();
}

private void path_Click(object sender, EventArgs e)
{


OpenFileDialog openFileDialog1 = new OpenFileDialog();

openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";

openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;

if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = openFileDialog1.FileName;

}

}





private void Cancel_Click(object sender, EventArgs e)
{
textBox1.Text = "";
richTextBox1.Text = "";

}

private void OK_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")//&& int.Parse(textBox1.Text) != 0)
{
//this.timer1.Interval = int.Parse(this.textBox1.Text);
richTextBox1.Text = "";
MessageBox.Show("Please choose a File!");
//this.richTextBox1.Text = "";

}


else

{
FileStream fs = new FileStream(textBox1.Text, FileMode.Open, FileAccess.Read);
StreamReader m_streamReader = new StreamReader(fs);


m_streamReader.BaseStream.Seek(0, SeekOrigin.Begin);

this.richTextBox1.Text = "";
string strLine = m_streamReader.ReadLine();


while (strLine != null)
{
this.richTextBox1.Text += strLine + "\n";
strLine = m_streamReader.ReadLine();

}


m_streamReader.Close();
string textline;

ArrayList text = new ArrayList();
StreamReader freader = File.OpenText(textBox1.Text);
while ((textline = freader.ReadLine()) != null)
{
if (textline.Length == 0)
continue;
text.Add(textline);
}


}

Form2 frm = new Form2();
frm.Show();

}



}
}



Form2



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;

namespace WindowsFormsApplication1
{
public partial class Form2 : Form

{
public Form2()

{
InitializeComponent();
}

private void richTextBox1_TextChanged(object sender, EventArgs e)
{

}


}
}

...全文
117 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
jshi123 2010-07-27
  • 打赏
  • 举报
回复
你希望Error1.txt文件中的这些数据在Form2上的图表中显示成什么样子?
denbes 2010-07-27
  • 打赏
  • 举报
回复

定义一个结构体
Struct XYZvalue
{
int x;
int y;
int z;
}
Form2中定义这样一个变量
public List<XYZvalue> list=null;
然后
将Form1中X,y,z点对象传过不来
Form2 frm=Form2();
frm.list=//form1中xyz点的集合
frm.Show();

happyrain2010 2010-07-27
  • 打赏
  • 举报
回复
在form构造函数中传过去
schnappie 2010-07-26
  • 打赏
  • 举报
回复
<a href=http://www.popo8.com target=_blank ><img src=http://www.popo8.com/files/albums/201006/1280155866.JPG ></a>
schnappie 2010-07-26
  • 打赏
  • 举报
回复
我是菜鸟,你们说的这些我都不知道。能不能写下代码,让我看懂,写个简单的例子能让我看懂就行。
schnappie 2010-07-26
  • 打赏
  • 举报
回复
楼上的,你看我写的程序了吗?我都没写x,y,z.
能不能写一下详细代码。
我从txt文档中读取了整个数据,但我不知道该如何给他区分成x,y,z

form2又该如何读取这三窜数呢?
mayonglong 2010-07-26
  • 打赏
  • 举报
回复
构造函数传参
静态变量
wuyq11 2010-07-26
  • 打赏
  • 举报
回复
form间传值定义属性
Form2 frm = new Form2(x,y,z);
frm.Show();
萤火架构 2010-07-26
  • 打赏
  • 举报
回复
看不到图,代码也没实质内容
读取出来,保存到一个集合中,自己定义坐标的基准点,然后调用画图的方法。

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧