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;
제 질문은, 어떻게 스트림 리더 sr을 Form1_paint 메서드의 button1_click 메서드에서 참조합니까?
이 질문에 대답하지만, 나는이 접근법에 의문을 제기합니다. 1. 모든 페인트에서 열린 스트림 2.ReadLine()을 유지하는 것이 매우 느릴 것입니다 3.파일이 끝날 때 –
응답을 보내 주셔서 감사합니다 답장을 주셔서 감사합니다 ... – Gary
당신이 제안한 솔루션을 나타내는 반면 제안 된 코드는 label1에 Form1_Paint 메서드의 strNumVertices 값을 채우지 않습니다 왜 이래요? – Gary