为何要这么复杂,用GDI+更好呀

解决方案 »

  1.   

    不晓得,我用的writefile API,不晓得filestream有没有影响!
      

  2.   

    我平时常用的是web编程,现在突然遇到winform编程了,二楼和三楼的能否给个例子,最好详细点的~~~谢谢了
      

  3.   

    去网上找justinio.cs,基本能满足你的大部分需求!
      

  4.   

    faint!仔细给你看了看!public void PrintLine(string str)
    {

    IntPtr iHandle = CreateFile(prnPort,  0x40000000, 0, 0, OPEN_EXISTING, 0, 0);///此处打开了,最后没有关闭!因此在打开的时候会产生错误!另外仔细看看你的0x40000000是不是正确的参数!关闭端口使用closehandle API,imports怎么写,自己查!CloseHandle(iHandle);//关闭文件流之后,添加这个!另外不建议你如此做!建议你先open,然后进行多个操作之后,最后close!
      

  5.   

    xxuu503 能不能给个详细点的代码~~~
    我对api函数是新手~~~
      

  6.   

    [DllImport("kernel32.dll")] public static extern Int32 CloseHandle
    ( IntPtr hObject ); //放在createfile函数后边声明一下public void PrintLine(string str)
    {

    IntPtr iHandle = CreateFile(prnPort,  0x40000000, 0, 0, OPEN_EXISTING, 0, 0);
    if(iHandle.ToInt32() == -1)
    {
    }
    else
    {
    FileStream fs = new FileStream(iHandle, FileAccess.ReadWrite);
    StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Default); //写数据
    sw.WriteLine(str); sw.Close();
    fs.Close();
    }
                               CloseHandle(iHandle);
    }
      

  7.   

    xxuu503 我用你的方法试过了~~还是不行~~ 
    能给给详细解决方法吗?现金100元求最终解决方法,不知道可以吗 ~~~~~ QQ:34646139 直接联系我也可以
      

  8.   

    钱箱也一样,在那个位置上加上closehandle
      

  9.   

    原理是这样子的:像com和lpt口,在《windows高级编程》书里说:这个叫做内核资源,如果一个程序打开了它,而不关闭的话,即使程序退出了,资源也不会被释放!你写的printline函数,先打开,然后按流写入,关闭流,却没有关闭端口!下次printline的时候,自然无法打开端口,因为已经被打开了!我猜测你的结果就是如此:打印一个命令后(可能是一行),无法执行下一个指令!
      

  10.   

    如果成的话,希望你把100元给我,正缺网费呢!呵呵!Joke!
      

  11.   

    我说到做到~~~解决以后直接给我你的帐号~~~转帐费用我付我打印的时候不是只打印一行,而是打印了5-6行以后才中断的因为是pos机的打印机,不能使用printdocument来打印,
      

  12.   

    public class LPTControl
    {
    [DllImport("kernel32.dll"]
    private static extern IntPtr CreateFile(string lpFileName,
    int dwDesiredAccess, 
    int dwShareMode, 
    int lpSecurityAttributes,
    int dwCreationDisposition ,
    int dwFlagsAndAttributes ,
    int hTemplateFile);[DllImport("kernel32.dll")]
    private static extern bool WriteFile(
    int hFile,
    byte[] lpBuffer,
    int nNumberOfBytesToWrite,
    ref int lpNumberOfBytesWritten,
    ref int i
    );[DllImport("kernel32.dll")]
    private static extern bool CloseHandle(
    IntPtr hObject
    );IntPtr iHandle;//定义端口句柄public bool open()//打开端口
    {
    IntPtr iHandle = CreateFile(prnPort,  0x40000000, 0, 0, OPEN_EXISTING, 0, 0);//打开
    if(iHandle!=IntPtr(-1))
    return true;
    else
    return false;
    }public bool Write(String Mystring)//写端口,返回true or false
    {
    return this.WriteFile(iHandle,System.Text.Encoding.Default.GetBytes(Mystring)
    ,System.Text.Encoding.Default.GetBytes(Mystring).length//查查看,不确定是这个属性
    ,ref 0,ref 0);
    }public bool Close()
    {
    return this.CloseHandle(iHandle);
    }
    }
      

  13.   

    我现在在学校机房,没有.net环境和并口设备,你先测试一下,看看如何!
      

  14.   

    聊了半天,终于搞出正确答案了!public class LPTControl
    {
    [StructLayout(LayoutKind.Sequential)]
            Private struct OVERLAPPED
    {
    int Internal;
    int InternalHigh;
    int Offset;
    int OffSetHigh;
    int hEvent;
    }
    [DllImport("kernel32.dll")]
    private static extern int CreateFile(
    string lpFileName,
    uint dwDesiredAccess,
    int dwShareMode,
    int lpSecurityAttributes,
    int dwCreationDisposition,
    int dwFlagsAndAttributes,
    int hTemplateFile
    );
    [DllImport("kernel32.dll")]
    private static extern bool WriteFile(
    int hFile,
    byte[] lpBuffer,
    int nNumberOfBytesToWrite,
    ref int lpNumberOfBytesWritten,
    ref OVERLAPPED lpOverlapped
    );
    [DllImport("kernel32.dll")]
    private static extern bool CloseHandle(
    int hObject
    );
    private int iHandle;
    public bool Open()
    {
    iHandle=CreateFile("lpt1",0x40000000,0,0,3,0,0);
    if(iHandle !=-1)
    {
    return true;
    }
    else
    {
    return false;
    }
    }
    public bool Write(String Mystring)
    {
    if(iHandle !=-1)
    {
    int i;
    OVERLAPPED x;
    byte() mybyte=System.Text.Encoding.Default.GetBytes(Mystring);
    return WriteFile(iHandle,mybyte,mybyte.Length
    ref i,ref x);
    }
    else
    {
    Throw new Exception("端口未打开!");
    }
    }
    public bool Close()
    {
    return CloseHandle(iHandle);
    }
    }
      

  15.   

    xxuu503(2005年CSDN MVH|被逼考六级|安心找工作ing!):
    你的LPTControl类中的write方法:
    int i;
    OVERLAPPED x;
    byte() mybyte=System.Text.Encoding.Default.GetBytes(Mystring);
    return WriteFile(iHandle,mybyte,mybyte.Length
    ref i,ref x);
    i和x如何赋值啊?是不是i=0;x=new OVERLAPPED();?