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,038

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


 

[.NET] ต้องการพิมพ์ใบสลิปโดยใช้เครื่องพิมพ์ใบเสร็จอย่างย่อ โดยใช้ 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 : 10053 Reply : 5
 

 

No. 1



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

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

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

แนะนำว่า......ทำมาก่อนครับ ติดตรงไหนค่อยเข้ามาถามครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-11-26 16:23:32 By : Dragons_first
 

 

No. 2



โพสกระทู้ ( 74,059 )
บทความ ( 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#)
1.printFont = new Font("Arial", 10);
2.PrintDocument pd = new PrintDocument();
3.pd.PrintPage += new PrintPageEventHandler
4.   (this.pd_PrintPage);
5.pd.Print();


pd_PrintPage จะถูกเรียกเมื่อแต่ละ page จะถูก print อ่าครับเพื่อที่จะเอาไว้ Set พวกขอบบนขอบลาง และเราต้องการ print ข้อมูลอะไรออกที่เครื่องพิมพ์ อะไรประมาณนี้อ่าครับ
Code (C#)
01.// The PrintPage event is raised for each page to be printed.
02.    private void pd_PrintPage(object sender, PrintPageEventArgs ev)
03.    {
04.        float linesPerPage = 0;
05.        float yPos = 0;
06.        int count = 0;
07.        float leftMargin = ev.MarginBounds.Left;
08.        float topMargin = ev.MarginBounds.Top;
09.        string line = null;
10. 
11.        // Calculate the number of lines per page.
12.        linesPerPage = ev.MarginBounds.Height /
13.           printFont.GetHeight(ev.Graphics);
14. 
15.        // Print each line of the file.
16.        while (count < linesPerPage &&
17.           ((line = streamToPrint.ReadLine()) != null))
18.        {
19.            yPos = topMargin + (count *
20.               printFont.GetHeight(ev.Graphics));
21.            ev.Graphics.DrawString(line, printFont, Brushes.Black,
22.               leftMargin, yPos, new StringFormat());
23.            count++;
24.        }
25. 
26.        // If more lines exist, print another page.
27.        if (line != null)
28.            ev.HasMorePages = true;
29.        else
30.            ev.HasMorePages = false;
31.    }


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


ตัวอย่าง Code ทั้งหมด
Code (C#)
001.using System;
002.using System.IO;
003.using System.Drawing;
004.using System.Drawing.Printing;
005.using System.Windows.Forms;
006. 
007. 
008.public partial class Form1 : System.Windows.Forms.Form
009.{
010.    private System.ComponentModel.Container components;
011.    private System.Windows.Forms.Button printButton;
012.    private Font printFont;
013.    private StreamReader streamToPrint;
014. 
015.    public Form1()
016.    {
017.        // The Windows Forms Designer requires the following call.
018.        InitializeComponent();
019.    }
020. 
021.    // The Click event is raised when the user clicks the Print button.
022.    private void printButton_Click(object sender, EventArgs e)
023.    {
024.        try
025.        {
026.            streamToPrint = new StreamReader
027.               ("C:\\My Documents\\MyFile.txt");
028.            try
029.            {
030.                printFont = new Font("Arial", 10);
031.                PrintDocument pd = new PrintDocument();
032.                pd.PrintPage += new PrintPageEventHandler
033.                   (this.pd_PrintPage);
034.                pd.Print();
035.            }
036.            finally
037.            {
038.                streamToPrint.Close();
039.            }
040.        }
041.        catch (Exception ex)
042.        {
043.            MessageBox.Show(ex.Message);
044.        }
045.    }
046. 
047.    // The PrintPage event is raised for each page to be printed.
048.    private void pd_PrintPage(object sender, PrintPageEventArgs ev)
049.    {
050.        float linesPerPage = 0;
051.        float yPos = 0;
052.        int count = 0;
053.        float leftMargin = ev.MarginBounds.Left;
054.        float topMargin = ev.MarginBounds.Top;
055.        string line = null;
056. 
057.        // Calculate the number of lines per page.
058.        linesPerPage = ev.MarginBounds.Height /
059.           printFont.GetHeight(ev.Graphics);
060. 
061.        // Print each line of the file.
062.        while (count < linesPerPage &&
063.           ((line = streamToPrint.ReadLine()) != null))
064.        {
065.            yPos = topMargin + (count *
066.               printFont.GetHeight(ev.Graphics));
067.            ev.Graphics.DrawString(line, printFont, Brushes.Black,
068.               leftMargin, yPos, new StringFormat());
069.            count++;
070.        }
071. 
072.        // If more lines exist, print another page.
073.        if (line != null)
074.            ev.HasMorePages = true;
075.        else
076.            ev.HasMorePages = false;
077.    }
078. 
079. 
080.    // The Windows Forms Designer requires the following procedure.
081.    private void InitializeComponent()
082.    {
083.        this.components = new System.ComponentModel.Container();
084.        this.printButton = new System.Windows.Forms.Button();
085. 
086.        this.ClientSize = new System.Drawing.Size(504, 381);
087.        this.Text = "Print Example";
088. 
089.        printButton.ImageAlign =
090.           System.Drawing.ContentAlignment.MiddleLeft;
091.        printButton.Location = new System.Drawing.Point(32, 110);
092.        printButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
093.        printButton.TabIndex = 0;
094.        printButton.Text = "Print the file.";
095.        printButton.Size = new System.Drawing.Size(136, 40);
096.        printButton.Click += new System.EventHandler(printButton_Click);
097. 
098.        this.Controls.Add(printButton);
099.    }
100. 
101.}


ใน .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 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





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