[ad_1]
このクエストを手伝ってくださいn ホテルの請求書に表示されるものと同じです
解決策 1
DGVPrinter printer = new DGVPrinter(); printer.PageSettings.PaperSize = new PaperSize("A4", 827, 1169); printer.PageSettings.Margins = new Margins(50, 50, 50, 50); string gstin = "GSTIN: 33DQHPK0895R1Z3"; string cellNumber = "Cell: 9443106555"; string officeName = "KAVIJAYA COMPUTERS"; string address = "24/41 Vishalam Complex, Ist Floor, Town Extension,"; string place = "Mayiladuthurai"; string email = "Email: kavijayacomputer@gmail.com"; DateTime currentDateTime = DateTime.Now; // Get the current date and time string customerName = GetCustomerName(); // Replace with the code to retrieve the customer name string customerAddress = GetCustomerAddress(); // Replace with the code to retrieve the customer address string customerPhone = GetCustomerPhone(); // Replace with the code to retrieve the customer phone number string customerEmail = GetCustomerEmail(); // Replace with the code to retrieve the customer email Font detailsFont = new Font(printer.SubTitleFont.FontFamily, 8, FontStyle.Regular); printer.SubTitleFont = detailsFont; Font customerDetailsFont = new Font(printer.SubTitleFont.FontFamily, 10, FontStyle.Bold); printer.SubTitleFont = customerDetailsFont; printer.SubTitleColor = Color.Black; printer.SubTitleFont = new Font(printer.SubTitleFont.FontFamily, 14, FontStyle.Bold); printer.SubTitleFont = customerDetailsFont; printer.SubTitleColor = Color.Red; printer.SubTitleFormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit | StringFormatFlags.FitBlackBox; printer.SubTitleAlignment = StringAlignment.Center; printer.Title = $"{gstin} {cellNumber}"; // Combine GSTIN and Cell into a single line printer.SubTitle = $"{officeName}\r\n"; printer.SubTitle += $"{address}\r\n"; // Add the address line separately printer.SubTitle += $"{place}"; printer.SubTitle += $"\r\n{email}"; printer.SubTitle += "\r\n".PadRight(75, '_'); // Add a line of underscores printer.SubTitle += $"\r\n\r\nCustomer Details"; printer.SubTitle += $"\r\nCustomer Name: {customerName}"; printer.SubTitle += $"\r\nCustomer Address: {customerAddress}"; printer.SubTitle += $"\r\nPhone: {customerPhone}"; printer.SubTitle += $"\r\nEmail: {customerEmail}"; printer.SubTitle += "\r\n".PadRight(75, '_'); // Add a line of underscores printer.SubTitleFormat = new StringFormat() { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center }; // Adjust the font size for GSTIN and Cell Font titleFont = new Font(printer.TitleFont.FontFamily, 10, FontStyle.Italic); // Set the desired font size for GSTIN and Cell printer.TitleFont = titleFont; printer.SubTitleColor = Color.DarkBlue; // Adjust the font and color for the address Font addressFont = new Font("Times New Roman", 13, FontStyle.Bold); // Set the desired font size and style for the address line printer.SubTitleFont = addressFont; printer.SubTitleColor = Color.DarkBlue; // Set the color to blue for the address PrintDocument printDocument = new PrintDocument(); // Create a new PrintDocument printDocument.DefaultPageSettings.PaperSize = new PaperSize("A4", 827, 1169); // Set the paper size to A4 printDocument.DefaultPageSettings.Landscape = false; // Set the orientation to portrait printDocument.DefaultPageSettings.Margins = new Margins(30, 30, 30, 30); printDocument.PrintPage += (printSender, printEventArgs) => { Graphics graphics = printEventArgs.Graphics; Font font = new Font("Arial", 8, FontStyle.Regular); SolidBrush brush = new SolidBrush(Color.Black); float x = printEventArgs.MarginBounds.Left; float y = printEventArgs.MarginBounds.Top; // Draw the column headers with decreased width graphics.DrawString("Product Name", font, brush, x, y); x += 100; graphics.DrawString("Quantity", font, brush, x, y); x += 80; graphics.DrawString("Rate", font, brush, x, y); x += 60; graphics.DrawString("Serial Number", font, brush, x, y); x += 100; graphics.DrawString("Warranty", font, brush, x, y); x += 80; graphics.DrawString("CGST %", font, brush, x, y); x += 60; graphics.DrawString("SGST %", font, brush, x, y); x += 60; graphics.DrawString("Total", font, brush, x, y); x += 40; y += font.GetHeight(); x = printEventArgs.MarginBounds.Left; // Get the values for the row string productName = txtproduct_name.Text; string quantity = txtQty.Text; string rate = txtRate.Text; string serialNumber = txtSerialNumber.Text; string warranty = txtWarranty.Text; string cgst = txtGST.Text; string sgst = txtSGST.Text; string totalValue = txtTotal.Text; // Draw the row values // Draw the column headers with decreased width graphics.DrawString("Product Name", font, brush, x, y); x += 100; graphics.DrawString("Quantity", font, brush, x, y); x += 80; graphics.DrawString("Rate", font, brush, x, y); x += 60; graphics.DrawString("Serial Number", font, brush, x, y); x += 100; graphics.DrawString("Warranty", font, brush, x, y); x += 80; graphics.DrawString("CGST %", font, brush, x, y); x += 60; graphics.DrawString("SGST %", font, brush, x, y); x += 60; graphics.DrawString("Total", font, brush, x, y); x += 40; // Add the footer section string footer = $"Discount: {txtDiscount.Text}%\r\n" + $"CGST: 9%\r\n" + $"SGST: 9%\r\n" + $"Grand Total: {txtGrandTotal.Text}\r\n" + "Thank you for doing business with us.\r\n" + $"Printed on: {DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")}"; float footerHeight = graphics.MeasureString(footer, font).Height; float availableSpace = printEventArgs.MarginBounds.Height - y; if (availableSpace >= footerHeight) { y += 10; // Add some vertical spacing before the footer graphics.DrawString(footer, font, brush, x, y); } else { printEventArgs.HasMorePages = false; } }; // Assign the PrintDocument to the DGVPrinter printer.PrintDocument = printDocument; // Set the paper size to A4 // Rest of the code remains the same printer.SubTitleFormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoClip; printer.PageNumbers = true; printer.PageNumberInHeader = false; printer.PorportionalColumns = true; printer.HeaderCellAlignment = StringAlignment.Near; printer.Footer = $"Discount: {txtDiscount.Text}%\nCGST: 9%\nSGST: 9%\nGrand Total: {txtGrandTotal.Text}\n\nThank you for doing business with us.\n\nPrinted on: {currentDateTime.ToString("dd/MM/yyyy HH:mm:ss")}"; printer.HeaderCellAlignment = StringAlignment.Near; printer.RowHeight = DGVPrinter.RowHeightSetting.CellHeight; printer.PorportionalColumns = true; printer.FooterSpacing = 15; printer.PrintPreviewDataGridView(dgvAddedProducts); printer.PorportionalColumns = true; printer.PrintDataGridView(dgvAddedProducts); MessageBox.Show("Transaction Completed Successfully");
[ad_2]
コメント