- J. Moreno --J. Moreno 您的代码有4个问题... * * 1。变量myPrintFilename没有被设置为 * * openFileDialog1.FileName 2.你正在使用Append应该是 * *使用AppendLine 3.你有 * * * sr.ReadLine之后的myGlobalStringBuilder而不是sb.Append之后(应该是 * * sb.AppendLine)4。你正在使用Lucinda 48,而不是什么 * *较小... There''s 4 things wrong with your code...* *1. the variable myPrintFilename isn''t being set to* *openFileDialog1.FileName 2. You are using Append when you should be* *using AppendLine 3. You have the myGlobalStringBuilder after the* * * sr.ReadLine instead of after the sb.Append (which should be* *sb.AppendLine) 4. You''re using Lucinda 48, instead of something* *smaller... 这里还有一个。这个: if((myStream = openFileDialog1.OpenFile())!= null) { 使用(myStream) { StreamReader sr = File.OpenText(openFileDialog1.FileName); string s = sr.ReadLine(); StringBuilder sb = new StringBuilder(); while(s!= null) { sb.Append(s); s = sr.ReadLine(); myGlobalStringBuilder.Append(s) ; //! ???为什么myGlobal不是 附加在这里? } sr.Close(); textBox1.Text = sb.ToString(); //这个 有效,在屏幕上显示文件文字textBox1 } } 注意myStream从未实际使用过。此外,在using-expression之外初始化是毫无意义的。 There''s one more here. This: if ((myStream = openFileDialog1.OpenFile()) !=null){using (myStream){StreamReader sr =File.OpenText(openFileDialog1.FileName);string s = sr.ReadLine();StringBuilder sb = new StringBuilder();while (s != null){sb.Append(s);s = sr.ReadLine(); myGlobalStringBuilder.Append(s); //!!! ??? Why is myGlobal notappending here?}sr.Close();textBox1.Text = sb.ToString(); //thisworks, to show the file text on the screen textBox1 }} Note how myStream is never actually used. Also, it is pointlesslyinitialized outside the using-expression. 这篇关于打印文件PrintDocument--我做错了什么?必须是愚蠢的东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-30 06:15