从记事本一次打印一行 [英] Print one line at a time from notepad
本文介绍了从记事本一次打印一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
以下是我用于从记事本打印epson存折打印机的代码
string name;
name = C:\\Display.txt;
// 打开文件。
FileStream fs = new FileStream(name,FileMode.Open);
// printFont = new Font(Lucida Console,9);
// 在文件上创建一个BinaryReader。
BinaryReader br = new BinaryReader(fs);
// 将一个大小足以保存文件内容的字节数组调暗。
字节 [] bytes = new 字节 [fs.Length];
int bSuccess = 0 ;
// 您的非托管指针。
IntPtr pUnmanagedBytes = new IntPtr ( 0 跨度>);
int nLength;
nLength = Convert.ToInt32(fs.Length);
// 将文件内容读入数组。
bytes = br.ReadBytes(nLength);
// 为这些字节分配一些非托管内存。
pUnmanagedBytes = Marshal。 AllocCoTaskMem(nLength);
// 将托管字节数组复制到非托管数组中。
Marshal。复制(字节, 0 ,pUnmanagedBytes,nLength);
PrtSetFont( 10002 );
PrtPosAbsV( 2 );
PrtPosAbsH( 5 );
PrtPosRelV( 2 );
PrtPosRelH( 1 );
fs.Close();
int lines1 = File.ReadAllLines(name).Count();
int Number1 = lines1 / 26 ;
if (lines1 > 26 )
{
File.WriteAllText( C:\\Display-1 .txt, String .Empty);
bSuccess = PrtWrite(pUnmanagedBytes,nLength);
}
这里我从记事本中取出格式化数据并写入另一个记事本并发送到PrtWrite(),这是一次打印数据。
现在我必须一次发送一行。
请告诉我如何执行此操作。
解决方案
您可以遍历文件的行,然后进行处理。请参阅 http://msdn.microsoft.com/en-us/library/ dd383503(v = vs.110).aspx [ ^ ]
有关如何使用File.ReadLines()循环遍历源文件行的示例
首先,你从记事本中找不到任何东西。
那些是文本文件,而不是记事本。在他们无法弄清楚你在谈论什么的时候开始混淆人们的垃圾之前,要弄清楚术语是正确的。
nLength =转换。 ToInt32(fs.Length);
为什么要尝试将整数转换为整数?
如果这些是文本文件那么你应阅读如何:从文件中读取文本 [ ^ ]。
Hi all
Below is the code i am using to print in epson passbook printer from notepad
string name;
name = "C:\\Display.txt";
// Open the file.
FileStream fs = new FileStream(name, FileMode.Open);
//printFont = new Font("Lucida Console", 9);
// Create a BinaryReader on the file.
BinaryReader br = new BinaryReader(fs);
// Dim an array of bytes big enough to hold the file's contents.
Byte[] bytes = new Byte[fs.Length];
int bSuccess=0;
// Your unmanaged pointer.
IntPtr pUnmanagedBytes = new IntPtr(0);
int nLength;
nLength = Convert.ToInt32(fs.Length);
// Read the contents of the file into the array.
bytes = br.ReadBytes(nLength);
// Allocate some unmanaged memory for those bytes.
pUnmanagedBytes = Marshal.AllocCoTaskMem(nLength);
// Copy the managed byte array into the unmanaged array.
Marshal.Copy(bytes, 0, pUnmanagedBytes, nLength);
PrtSetFont(10002);
PrtPosAbsV(2);
PrtPosAbsH(5);
PrtPosRelV(2);
PrtPosRelH(1);
fs.Close();
int lines1 = File.ReadAllLines(name).Count();
int Number1 = lines1 / 26;
if (lines1 > 26)
{
File.WriteAllText("C:\\Display-1.txt", String.Empty);
bSuccess = PrtWrite(pUnmanagedBytes, nLength);
}
Here i am taking the formatted data from notepad and writing to another notepad and sending to PrtWrite() which is printing the data at a time.
Now i have to send one line at a time.
Please tell me how to do this.
解决方案
You can loop through the lines of the file and then do your processing. See http://msdn.microsoft.com/en-us/library/dd383503(v=vs.110).aspx[^]
for an example of how to loop through the lines of your source file using File.ReadLines()
First, you're not going anything at all "from notepad".
Those a "text files", not "notepads". Get the terminology correct before you start confusing the crap out of people when they can't figure out what you're talking about.
nLength = Convert.ToInt32(fs.Length);
Why are you trying to convert an integer to an integer?
Also if these are text files then you should read How to: Read Text from a File[^].
这篇关于从记事本一次打印一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文