Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > ต้องการพิมพ์ใบสลิปโดยใช้เครื่องพิมพ์ใบเสร็จอย่างย่อ โดยใช้ C#



 

ต้องการพิมพ์ใบสลิปโดยใช้เครื่องพิมพ์ใบเสร็จอย่างย่อ โดยใช้ C#

 



Topic : 069581



โพสกระทู้ ( 3 )
บทความ ( 0 )



สถานะออฟไลน์




คือผมกำลังทำโปรเจ็คเกี่ยวกับเครื่องหยอดเหรียญ โดยให้ตัวโปรแกรมสามารถพิมพ์ใบเสร็จอย่างย่อได้ โดยใช้ c# ซึ่งประกอบไปด้วยชื่อผู้เสียเงิน, วันที่, จำนวนเงิน เป็นต้น ไม่ทราบท่านใด้พอจะแนะนำให้ได้บ้างครับ



Tag : .NET, C#







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-11-26 14:51:57 By : sseiyatep View : 9805 Reply : 5
 

 

No. 1



โพสกระทู้ ( 3,748 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์
Facebook

แนะนำว่า......ทำมาก่อนครับ ติดตรงไหนค่อยเข้ามาถามครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-11-26 16:23:32 By : Dragons_first
 


 

No. 2



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

เท่าที่เคยทำคือมันจะต้องมีรุ่นของ Printer ก่อนครับ จากนั้นก็ออกแบบตาม Template ที่ Driver รุ่น นั้น ๆ มีมาให้ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-11-27 08:04:34 By : webmaster
 

 

No. 3



โพสกระทู้ ( 3 )
บทความ ( 0 )



สถานะออฟไลน์


ท่าน mr.win ช่วยแนะนำ code คร่าวๆ ให้หน่อยครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-12-04 07:20:44 By : sseiyatep
 


 

No. 4



โพสกระทู้ ( 169 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook Blogger

หวัดดีครับส่วนตัวผมไม่เคยเขียนติดต่อกับเครื่องพิมพ์แบบใบเสร็จนะครับแต่คิดว่าน่าจะเหมือนกันเครื่องพิมพ์ทั่วๆไป ผมลองหาดู .Net support เรื่องพวกนี้อยู่ครับตามลิงค์ด้านล่างเลยครับ

http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx
http://support.microsoft.com/kb/322091

ลิงค์อันสองจะยากหน่อยผมคิดว่ามันเป็นการส่ง Raw data ไปที่เครื่อง printer เลย ให้ลองทำอันลิงค์แรกดีกว่าง่ายกว่าครับ

ก่อนอื่นเลยต้อง Set printer และ call back function ก่อนครับ
Code (C#)
                printFont = new Font("Arial", 10);
                PrintDocument pd = new PrintDocument();
                pd.PrintPage += new PrintPageEventHandler
                   (this.pd_PrintPage);
                pd.Print();


pd_PrintPage จะถูกเรียกเมื่อแต่ละ page จะถูก print อ่าครับเพื่อที่จะเอาไว้ Set พวกขอบบนขอบลาง และเราต้องการ print ข้อมูลอะไรออกที่เครื่องพิมพ์ อะไรประมาณนี้อ่าครับ
Code (C#)
// The PrintPage event is raised for each page to be printed.
    private void pd_PrintPage(object sender, PrintPageEventArgs ev)
    {
        float linesPerPage = 0;
        float yPos = 0;
        int count = 0;
        float leftMargin = ev.MarginBounds.Left;
        float topMargin = ev.MarginBounds.Top;
        string line = null;

        // Calculate the number of lines per page.
        linesPerPage = ev.MarginBounds.Height /
           printFont.GetHeight(ev.Graphics);

        // Print each line of the file.
        while (count < linesPerPage &&
           ((line = streamToPrint.ReadLine()) != null))
        {
            yPos = topMargin + (count *
               printFont.GetHeight(ev.Graphics));
            ev.Graphics.DrawString(line, printFont, Brushes.Black,
               leftMargin, yPos, new StringFormat());
            count++;
        }

        // If more lines exist, print another page.
        if (line != null)
            ev.HasMorePages = true;
        else
            ev.HasMorePages = false;
    }


เมื่อ call back function ถูกเรียกเราก็แค่บอกว่าต้องการ print อะไร เช่นในกรณีนี้เราต้องการจะ print ข้อมูลที่อยู่ใน Text file "C:\\My Documents\\MyFile.txt" ที่เก็บอยู่ใน streamToPrint
Code (C#)
        // Print each line of the file.
        while (count < linesPerPage &&
           ((line = streamToPrint.ReadLine()) != null))
        {
            yPos = topMargin + (count *
               printFont.GetHeight(ev.Graphics));
            ev.Graphics.DrawString(line, printFont, Brushes.Black,
               leftMargin, yPos, new StringFormat());
            count++;
        }


ตัวอย่าง Code ทั้งหมด
Code (C#)
using System;
using System.IO;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;


public partial class Form1 : System.Windows.Forms.Form
{
    private System.ComponentModel.Container components;
    private System.Windows.Forms.Button printButton;
    private Font printFont;
    private StreamReader streamToPrint;

    public Form1()
    {
        // The Windows Forms Designer requires the following call.
        InitializeComponent();
    }

    // The Click event is raised when the user clicks the Print button.
    private void printButton_Click(object sender, EventArgs e)
    {
        try
        {
            streamToPrint = new StreamReader
               ("C:\\My Documents\\MyFile.txt");
            try
            {
                printFont = new Font("Arial", 10);
                PrintDocument pd = new PrintDocument();
                pd.PrintPage += new PrintPageEventHandler
                   (this.pd_PrintPage);
                pd.Print();
            }
            finally
            {
                streamToPrint.Close();
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

    // The PrintPage event is raised for each page to be printed.
    private void pd_PrintPage(object sender, PrintPageEventArgs ev)
    {
        float linesPerPage = 0;
        float yPos = 0;
        int count = 0;
        float leftMargin = ev.MarginBounds.Left;
        float topMargin = ev.MarginBounds.Top;
        string line = null;

        // Calculate the number of lines per page.
        linesPerPage = ev.MarginBounds.Height /
           printFont.GetHeight(ev.Graphics);

        // Print each line of the file.
        while (count < linesPerPage &&
           ((line = streamToPrint.ReadLine()) != null))
        {
            yPos = topMargin + (count *
               printFont.GetHeight(ev.Graphics));
            ev.Graphics.DrawString(line, printFont, Brushes.Black,
               leftMargin, yPos, new StringFormat());
            count++;
        }

        // If more lines exist, print another page.
        if (line != null)
            ev.HasMorePages = true;
        else
            ev.HasMorePages = false;
    }


    // The Windows Forms Designer requires the following procedure.
    private void InitializeComponent()
    {
        this.components = new System.ComponentModel.Container();
        this.printButton = new System.Windows.Forms.Button();

        this.ClientSize = new System.Drawing.Size(504, 381);
        this.Text = "Print Example";

        printButton.ImageAlign =
           System.Drawing.ContentAlignment.MiddleLeft;
        printButton.Location = new System.Drawing.Point(32, 110);
        printButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
        printButton.TabIndex = 0;
        printButton.Text = "Print the file.";
        printButton.Size = new System.Drawing.Size(136, 40);
        printButton.Click += new System.EventHandler(printButton_Click);

        this.Controls.Add(printButton);
    }

}


ใน .Net มี class ให้ใช้มากครับลองศึกษาดูนะครับ

ฝาก Like ด้วยนะครับ
http://www.facebook.com/pages/PStudio-Development-Store/284410714927365?sk=wall


ประวัติการแก้ไข
2011-12-05 15:35:32
2011-12-05 15:36:33
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-12-05 15:33:08 By : pStudio
 


 

No. 5

Guest


ถ้ามีปัญหาเรื่องเครื่องพิมพ์ใบเสร็จอย่างย่อย สามารถโทรมาปรึกษาได้ที่ 081-6103941 ทางเรามีเจ้าหน้าที่ที่มีความชำนาญเฉพาะทางแนะนำได้ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-02-11 11:40:36 By : ทรัตน์
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ต้องการพิมพ์ใบสลิปโดยใช้เครื่องพิมพ์ใบเสร็จอย่างย่อ โดยใช้ C#
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่