OO很新,所以請客氣。用兩種方法引用StreamReader
我已經創建了一個方法,當點擊button1時,打開文件對話框並將內容讀入流讀取器sr;
public void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
label1.Text = openFileDialog1.FileName;
StreamReader sr = new StreamReader(label1.Text);
String strNumVertices = sr.ReadLine();
label2.Text = strNumVertices;
}
}
其他代碼在Form1_Paint方法中運行。
public void Form1_Paint(object sender, PaintEventArgs e)
perspectiveMatrix = new Gmatrix("perspective");
translationMatrix = new Gmatrix("translation");
scalingMatrix = new Gmatrix("scaling");
perspectiveMatrix.initAsPerspectiveMatrix(300);
scalingMatrix.initAsScalingMatrix(10, 10, 10);
translationMatrix.initAsTranslationMatrix(150, 50, 1200);
String strNumVertices = sr.ReadLine();
label1.Text = strNumVertices;
我的問題是,如何從Form1_paint方法中的button1_click方法引用流讀取器sr?
雖然這確實回答了這個問題,但我會質疑這種方法 - 1.在每個繪畫中留下一個打開的流2.ReadLine()將會非常緩慢3。當文件到達它將炸燬 – 2011-03-23 12:21:39
感謝您的回覆... – Gary 2011-03-23 13:02:55
您建議的代碼,雖然它代表我正在尋找的解決方案,但它不會在Form1_Paint方法中使用strNumVertices的值填充label1 ,這是爲什麼呢? – Gary 2011-03-23 13:09:22