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 > รบกวนขอวิธี สั่งพิมพ์ textbox 5 ครั้ง ให้ random ตัวเลขที่อยู่ใน textbox โดยนับจาก textbox อันแรก



 

รบกวนขอวิธี สั่งพิมพ์ textbox 5 ครั้ง ให้ random ตัวเลขที่อยู่ใน textbox โดยนับจาก textbox อันแรก

 



Topic : 127043



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



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



รบกวนขอวิธี สั่งพิมพ์ textbox 5 ครั้ง ให้ random ตัวเลขที่อยู่ใน textbox โดยนับจาก textbox อันแรก
ผมพิมพ์ตัวเลขลงใน textbox1.text เช่นพิมพ์เลข 10 แล้วสั่งพิมพ์ออกไปที่กระดาษ A4 ตามตำแหน่ง x, y ก็จะแสดงเลข 10 ได้ เแต่ติดปัญหาตรงที่ว่า ผมต้องการพิมพ์หลายๆ แผ่นเช่นต้องการพิมพ์ทั้งหมด 5 แผ่นออกไปยังกระดาษ A4 5 ใบ โดยใส่จำนวนแผ่นที่ต้องการใน textbox2.text เมื่อกด button print แล้วให้
แผ่นที่ 1 มีหมายเลข 10 แสดงอยู่
แผ่นที่ 2 มีหมายเลข 11 แสดงอยู่
แผ่นที่ 3 มีหมายเลข 12 แสดงอยู่
แผ่นที่ 4 มีหมายเลข 13 แสดงอยู่
แผ่นที่ 5 มีหมายเลข 14 แสดงอยู่

กดพิมพ์แค่ครั้งเดียว ออกมา 5 แผ่น แต่ละแผ่นเรียงตัวเลขกันไป นับจากตัวเลขครั้งแรกเป็นหลัก
รบกวนวิธีทำด้วยครับ



Tag : .NET, VS 2012 (.NET 4.x)







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2017-04-01 11:46:13 By : sakkapong View : 976 Reply : 10
 

 

No. 1



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



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

ลองศึกษาการเพิ่มหน้ากระดาษ ดูครับ

ปล. นี่ไม่ใช่การ random นะครับ เพราะมันเพิ่มขึ้นทีละ 1 แต่คนละหน้า เหมือนเราใส่หน้ากระดาษ ครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-04-01 12:37:10 By : lamaka.tor
 


 

No. 2



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



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

Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TORServices.DatabaseTor
{
    public class PrintDataGridView
    {
        #region Variables

        int iCellHeight = 0; //Used to get/set the datagridview cell height
        int iTotalWidth = 0; //
        int iRow = 0;//Used as counter
        bool bFirstPage = false; //Used to check whether we are printing first page
        bool bNewPage = false;// Used to check whether we are printing a new page
        int iHeaderHeight = 0; //Used for the header height
        System.Drawing.StringFormat strFormat; //Used to format the grid rows.
        List<double> arrColumnLefts = new List<double>();//Used to save left coordinates of columns
        List<double> arrColumnWidths = new List<double>();//Used to save column widths
        private System.Drawing.Printing.PrintDocument _printDocument = new System.Drawing.Printing.PrintDocument();
        private System.Windows.Forms.DataGridView gw = new System.Windows.Forms.DataGridView();
        private string _ReportHeader;
        int iCount = 0;
        #endregion

        public PrintDataGridView(System.Windows.Forms.DataGridView gridview, string ReportHeader)
        {
            _printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument_PrintPage);
            _printDocument.BeginPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_BeginPrint);
            gw = gridview;
            _ReportHeader = ReportHeader;

        }

        public void PrintForm()
        {

            System.Windows.Forms.PrintDialog printDialog = new System.Windows.Forms.PrintDialog();
            printDialog.Document = _printDocument;
            printDialog.UseEXDialog = true;
            //Get the document
            if (System.Windows.Forms.DialogResult.OK == printDialog.ShowDialog())
            {
                _printDocument.DocumentName = _ReportHeader + string.Format("{0:yyyyMMdd hhmmss}", DateTime.Now);
                _printDocument.Print();
            }

        }
        #region Begin Print Event Handler
        /// <span class="code-SummaryComment"><summary></span>
        /// Handles the begin print event of print document
        /// <span class="code-SummaryComment"></summary></span>
        /// <span class="code-SummaryComment"><param name=""sender""></param></span>
        /// <span class="code-SummaryComment"><param name=""e""></param></span>
        private void printDocument_BeginPrint(object sender,
            System.Drawing.Printing.PrintEventArgs e)
        {

            strFormat = new System.Drawing.StringFormat();
            strFormat.Alignment = System.Drawing.StringAlignment.Near;
            strFormat.LineAlignment = System.Drawing.StringAlignment.Center;
            strFormat.Trimming = System.Drawing.StringTrimming.EllipsisCharacter;

            if (arrColumnLefts != null) arrColumnLefts.Clear();
            if (arrColumnWidths != null) arrColumnWidths.Clear();
            arrColumnLefts = new List<double>();
            arrColumnWidths = new List<double>();
            iCellHeight = 0;
            iCount = 0;
            bFirstPage = true;
            bNewPage = true;

            // Calculating Total Widths
            iTotalWidth = 0;
            foreach (System.Windows.Forms.DataGridViewColumn dgvGridCol in gw.Columns)
            {
                iTotalWidth += dgvGridCol.Width;
            }
        }
        #endregion

        #region Print Page Event
        /// <span class="code-SummaryComment"><summary></span>
        /// Handles the print page event of print document
        /// <span class="code-SummaryComment"></summary></span>
        /// <span class="code-SummaryComment"><param name=""sender""></param></span>
        /// <span class="code-SummaryComment"><param name=""e""></param></span>
        private void printDocument_PrintPage(object sender,
            System.Drawing.Printing.PrintPageEventArgs e)
        {
            //Set the left margin
            int iLeftMargin = 50;// e.MarginBounds.Left;
            //Set the top margin
            int iTopMargin = e.MarginBounds.Top;
            //Whether more pages have to print or not
            bool bMorePagesToPrint = false;
            int iTmpWidth = 0;

            //For the first page to print set the cell width and header height
            if (bFirstPage)
            {
                foreach (System.Windows.Forms.DataGridViewColumn GridCol in gw.Columns)
                {
                    iTmpWidth = (int)(System.Math.Floor((double)((double)GridCol.Width /
                        (double)iTotalWidth * (double)iTotalWidth *
                        ((double)e.MarginBounds.Width / (double)iTotalWidth))));

                    iHeaderHeight = (int)(e.Graphics.MeasureString(GridCol.HeaderText,
                        GridCol.InheritedStyle.Font, iTmpWidth).Height) + 11;

                    // Save width and height of headers
                    arrColumnLefts.Add(iLeftMargin);
                    arrColumnWidths.Add(iTmpWidth);
                    iLeftMargin += iTmpWidth;
                }
            }
            //Loop till all the grid rows not get printed
            while (iRow <= gw.Rows.Count - 1)
            {
                System.Windows.Forms.DataGridViewRow GridRow = gw.Rows[iRow];
                //Set the cell height
                iCellHeight = GridRow.Height + 5;
                int iCount = 0;
                //Check whether the current page settings allows more rows to print
                if (iTopMargin + iCellHeight >= e.MarginBounds.Height + e.MarginBounds.Top)
                {
                    bNewPage = true;
                    bFirstPage = false;
                    bMorePagesToPrint = true;
                    break;
                }
                else
                {
                    if (bNewPage)
                    {
                        //Draw Header
                        e.Graphics.DrawString(_ReportHeader,
                            new System.Drawing.Font(gw.Font, System.Drawing.FontStyle.Bold),
                            System.Drawing.Brushes.Black, e.MarginBounds.Left,
                            e.MarginBounds.Top - e.Graphics.MeasureString(_ReportHeader,
                            new System.Drawing.Font(gw.Font, System.Drawing.FontStyle.Bold),
                            e.MarginBounds.Width).Height - 13);

                        String strDate = DateTime.Now.ToLongDateString() + " " +
                            DateTime.Now.ToShortTimeString();
                        //Draw Date
                        e.Graphics.DrawString(strDate,
                            new System.Drawing.Font(gw.Font, System.Drawing.FontStyle.Bold), System.Drawing.Brushes.Black,
                            e.MarginBounds.Left +
                            (e.MarginBounds.Width - e.Graphics.MeasureString(strDate,
                            new System.Drawing.Font(gw.Font, System.Drawing.FontStyle.Bold),
                            e.MarginBounds.Width).Width),
                            e.MarginBounds.Top - e.Graphics.MeasureString(_ReportHeader,
                            new System.Drawing.Font(new System.Drawing.Font(gw.Font, System.Drawing.FontStyle.Bold),
                            System.Drawing.FontStyle.Bold), e.MarginBounds.Width).Height - 13);

                        //Draw Columns                 
                        iTopMargin = e.MarginBounds.Top;
                        foreach (System.Windows.Forms.DataGridViewColumn GridCol in gw.Columns)
                        {
                            e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.LightGray),
                                new System.Drawing.Rectangle((int)arrColumnLefts[iCount], iTopMargin,
                                (int)arrColumnWidths[iCount], iHeaderHeight));

                            e.Graphics.DrawRectangle(System.Drawing.Pens.Black,
                                new System.Drawing.Rectangle((int)arrColumnLefts[iCount], iTopMargin,
                                (int)arrColumnWidths[iCount], iHeaderHeight));

                            e.Graphics.DrawString(GridCol.HeaderText,
                                GridCol.InheritedStyle.Font,
                                new System.Drawing.SolidBrush(GridCol.InheritedStyle.ForeColor),
                                new System.Drawing.RectangleF((int)arrColumnLefts[iCount], iTopMargin,
                                (int)arrColumnWidths[iCount], iHeaderHeight), strFormat);
                            iCount++;
                        }
                        bNewPage = false;
                        iTopMargin += iHeaderHeight;
                    }
                    iCount = 0;
                    //Draw Columns Contents                
                    foreach (System.Windows.Forms.DataGridViewCell Cel in GridRow.Cells)
                    {
                        if (Cel.Value != null)
                        {
                            e.Graphics.DrawString(Cel.Value.ToString(),
                                Cel.InheritedStyle.Font,
                                new System.Drawing.SolidBrush(Cel.InheritedStyle.ForeColor),
                                new System.Drawing.RectangleF((int)arrColumnLefts[iCount],
                                (float)iTopMargin,
                                (int)arrColumnWidths[iCount], (float)iCellHeight),
                                strFormat);
                        }
                        //Drawing Cells Borders 
                        e.Graphics.DrawRectangle(System.Drawing.Pens.Black,
                            new System.Drawing.Rectangle((int)arrColumnLefts[iCount], iTopMargin,
                            (int)arrColumnWidths[iCount], iCellHeight));
                        iCount++;
                    }
                }
                iRow++;
                iTopMargin += iCellHeight;
            }
            //If more lines exist, print another page.
            if (bMorePagesToPrint)
                e.HasMorePages = true;
            else
                e.HasMorePages = false;
        }
        #endregion


    }
   

}



มองประเด็นไปที่ Graphics.DrawString หรือพวก Draw ต่างของ Document
มองว่าการพิมพ์งานก็คือ การ ใช้งาน Image/picture/Graphics หรือการเรารูปมายัดลงเครื่องปริ้นนั่นเองครับ
แรกผมไปมุ่งที่ Document เล่นเอางง แต่พอมองว่ามันมาจาก รูปภาพ ทุกอย่างที่ทำเป็นรูปได้ก็พิมได้ ก็เลยง่ายขึ้น ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-04-01 12:43:39 By : lamaka.tor
 

 

No. 3



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



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


บอกตรง ๆ ว่าผมอ่านแล้วไม่เข้าใจ
อ้างอิงจากคุณ TOR_CHEMISTRY น่ะครับ

ถ้าอยากพิมพ์หมายเลขในกระดาษ
และให้มันเพิ่มไปเรื่อย ๆ
ผมว่าทำใน Crystal Report ก็ได้มั้งครับ

ส่งค่าไป แล้วให้บวกกับเลขหน้าปัจจุบัน
ก็น่าจะทำได้
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-04-01 15:50:57 By : fonfire
 


 

No. 4



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



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

sadfwqer

ตามภาพครับ
ID ตอนนี้เท่ากับ 93
1.เมื่อกด print ให้พิมพ์ QRcode ออกมาแล้ว ID จาก 93 ให้เป็น 94 จำนวนแผ่นจาก 5 เหลือ 4
2.ถ้าจำนวนแผ่นเท่ากับ 4 เหลือ ให้พิมพ์ QRcode ออกมาแล้ว ID จาก 93 ให้เป็น 94 จำนวนแผ่นจาก 5 เหลือ 4
3.เมื่อกด print ให้พิมพ์ QRcode ออกมาแล้ว จำนวนแผ่นจาก 3 เหลือ 2 ID เปลี่ยนเป็น 96
4.เมื่อกด print ให้พิมพ์ QRcode ออกมาแล้ว จำนวนแผ่นจาก 2 เหลือ 1 ID เปลี่ยนเป็น 97
5.เมื่อกด print ให้พิมพ์ QRcode ออกมาแล้ว จำนวนแผ่นจาก 1 เหลือ 0 ID เปลี่ยนเป็น 98
ต่อไปถ้ากด print อีกจะไม่สามารถพิมพ์ได้เพราะจำนวนแผ่น = 0
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-04-01 16:41:05 By : sakkapong
 


 

No. 5



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



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

แก้ไขข้างบนก่อนหน้านี้นะครับ

ตามภาพครับ
ID ตอนนี้เท่ากับ 93
1.เมื่อกด print ให้พิมพ์ QRcode ออกมาแล้ว ID จาก 93 ให้เป็น 94 จำนวนแผ่นจาก 5 เหลือ 4
2.ถ้าจำนวนแผ่นเท่ากับ 4 ให้พิมพ์ QRcode ออกมาแล้ว ID จาก 94 ให้เป็น 95 จำนวนแผ่นจาก 4 เหลือ 3
3.ถ้าจำนวนแผ่นเท่ากับ 3 ให้พิมพ์ QRcode ออกมาแล้ว ID จาก 95 ให้เป็น 96 จำนวนแผ่นจาก 3 เหลือ 2
4.ถ้าจำนวนแผ่นเท่ากับ 2 ให้พิมพ์ QRcode ออกมาแล้ว ID จาก 96 ให้เป็น 97 จำนวนแผ่นจาก 2 เหลือ 1
5.ถ้าจำนวนแผ่นเท่ากับ 1 ให้พิมพ์ QRcode ออกมาแล้ว ID จาก 97 ให้เป็น 98 จำนวนแผ่นจาก 1 เหลือ 0
ถ้าจำนวนแผ่นเท่ากับ 0 ให้หยุดพิมพ์ไม่ต้องทำอะไร

แบบนี้ครับ
ขอบคุณครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-04-01 16:45:46 By : sakkapong
 


 

No. 6

Guest



@K-YON


Quote:
ฮักที่แลกด้วยแหกกฏฟ้า ถึงมีน้ำตาเข้ามาแต่งเติม
ความปวดร้าวสิเข้ามาเสริม บ่เคยคิดย่าน


สำเนาและต้องการเลขที่กำกับ


กระชับ ความต้องการโดย "ย่อความต้องการ/อธิบายยิ่งย่อลงไปอีก"
--- ถ้าคุณยังไม่เข้าใจ ผมสมมุติว่า ผมชื่อ นายละเอียด โดยที่คนฟัง/อื่นฯที่เกี่ยวข้อง
------ ไม่จำเป็นต้องถามนามสกุลของผม

อีฟเด็นเอว มันก็สำคัญแต่อย่างอื่นฯมันก็สำคัญไม่น้อยไปกว่านี้


ปล. ผมชื่อนายละเอียด ผมคงไม่จำเป็นต้องมีนามสกุลว่าละเอียด กำกับ"มั้ง"
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-04-01 17:24:27 By : หน้าฮี
 


 

No. 7

Guest


ผมเคยด่าคนต่อหน้าและลับหลัง
ผมถามว่า : ตรูแอบด่า/ด่าตรงฯ ทำไมเอ็งถึงยังหัวเราะได้ว่ะ?
คนถูกด่า: ผมเป็นคนมองโลกในแง่ดี ทุกฯคำชม/คำด่า ผมถือว่าเป็นประสบการ์ณ

+++++ 55555


ผมอยากได้ลูกพี่ที่คิดได้แบบนี้จริงฯ ไม่ต้องมากขอแค่มีแค่คนเดียวบนโลกใบนี้

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-04-01 17:32:45 By : หน้าฮี
 


 

No. 8

Guest


โลกใบนี้มันกว้าง แต่ความรู้ด้านคอมพิวเตอร์(ในเมืองไทย) มันยังคงคำว่า "แคบ"
--- โอกาสที่เราจะเจอกันด้วยความบังเอิญมันก็เป็นไปได้
--- ไม่รู้ใครเป็นใคร จริงหรือโกหก มันก็ยังไม่ได้นิยามให้ตรงกัน

พึงระมัดระวัง


ปล. +55555
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-04-01 17:43:52 By : หน้าฮี
 


 

No. 9



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



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

555 ยังไม่เข้าใจขอเอากลับไปนอนคิดก่อน
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-04-01 17:44:47 By : sakkapong
 


 

No. 10



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



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

ตอบความคิดเห็นที่ : 3 เขียนโดย : fonfire เมื่อวันที่ 2017-04-01 15:50:57
รายละเอียดของการตอบ ::
เป็นคำเปรียบเปรยให้มองเห็นภาพปกติครับ
ไม่ได้เจาะจงว่าเป็นจำนวนหน้า
แค่ส่วนใหญ่ที่เห็นง่ายสุดก็จะเป็นจำนวนหน้าแค่นั้นเองครับ

พูดง่ายๆคือพอเราพูดถึง ตัวเลขที่รันต่อกัน ก็จะนึกถึง ตัวเลขจำนวนหน้ามาก่อนเพื่อน ประมาณนั้นครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-04-01 18:46:52 By : lamaka.tor
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : รบกวนขอวิธี สั่งพิมพ์ textbox 5 ครั้ง ให้ random ตัวเลขที่อยู่ใน textbox โดยนับจาก textbox อันแรก
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 03
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 อัตราราคา คลิกที่นี่