- Print 기본 기능 추가

Print 가능한 형태를 추가
This commit is contained in:
2023-09-03 22:14:12 +09:00
parent 3e0ea8840f
commit 8f422f84d2
3 changed files with 64 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing.Printing;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
@@ -167,10 +168,18 @@ namespace HSUCO_Cargo_Garage_Operation_Program.CustomUserControl
private void metroButton_Certificate_Click(object sender, EventArgs e) private void metroButton_Certificate_Click(object sender, EventArgs e)
{ {
var allCount = dataGridView_List.SelectedRows.Count; //var allCount = dataGridView_List.SelectedRows.Count;
if (allCount == 0) return; //if (allCount == 0) return;
// TODO: 증명서 인쇄 // TODO: 증명서 인쇄
// PRINT // PRINT
Print print = new Print();
PrintDocument printDocument = new PrintDocument();
printDocument.PrintPage += new PrintPageEventHandler(print.PrintPage);
PrintPreviewDialog printPreviewDialog = new PrintPreviewDialog();
printPreviewDialog.Document = printDocument;
printPreviewDialog.ShowDialog();
} }
} }
} }

View File

@@ -162,6 +162,7 @@
<Compile Include="Master.Designer.cs"> <Compile Include="Master.Designer.cs">
<DependentUpon>Master.cs</DependentUpon> <DependentUpon>Master.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Print.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="CustomForm\Promotion.resx"> <EmbeddedResource Include="CustomForm\Promotion.resx">

View File

@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HSUCO_Cargo_Garage_Operation_Program
{
internal class Print
{
public void PrintPage(object sender, PrintPageEventArgs e)
{
// 테두리?
e.Graphics.DrawRectangle(new Pen(Brushes.Black, 3), e.MarginBounds.Top, e.MarginBounds.Left, e.MarginBounds.Width, e.MarginBounds.Height);
string text = "화물차고지 사용신고확인서";
Font font = new Font("맑은 고딕", 30, FontStyle.Bold);
int totalWidth = (int)e.PageBounds.Width;
int totalHeight = (int)e.PageBounds.Height;
e.Graphics.DrawString("제 2023-01호", new Font("맑은 고딕", 12), Brushes.Black, e.MarginBounds.Left + 10, e.MarginBounds.Top + 10);
SizeF textSize = e.Graphics.MeasureString(text, font);
float textX = (totalWidth - textSize.Width) / 2;
e.Graphics.DrawString(text, font, Brushes.Black, textX, e.MarginBounds.Top + 150);
e.Graphics.DrawString("사용자 성명 : ", new Font("맑은 고딕", 12), Brushes.Black, e.MarginBounds.Left + 50, e.MarginBounds.Top + 300);
e.Graphics.DrawString("주소 : ", new Font("맑은 고딕", 12), Brushes.Black, e.MarginBounds.Left + 50, e.MarginBounds.Top + 350);
e.Graphics.DrawString("차량번호 : ", new Font("맑은 고딕", 12), Brushes.Black, e.MarginBounds.Left + 50, e.MarginBounds.Top + 400);
e.Graphics.DrawString("사용기한 : 2023-01-01 ~ 2023-12-31", new Font("맑은 고딕", 12), Brushes.Black, e.MarginBounds.Left + 50, e.MarginBounds.Top + 450);
e.Graphics.DrawString("내용", new Font("맑은 고딕", 12), Brushes.Black, e.MarginBounds.Left + 50, e.MarginBounds.Top + 500);
text = "2023년 01월 01일";
font = new Font("맑은 고딕", 15);
textSize = e.Graphics.MeasureString(text, font);
textX = (totalWidth - textSize.Width) / 2;
e.Graphics.DrawString(text, font, Brushes.Black, textX, e.MarginBounds.Top + 700);
text = "화성도시공사 화물차주차장 담당자";
font = new Font("맑은 고딕", 20);
textSize = e.Graphics.MeasureString(text, font);
textX = (totalWidth - textSize.Width) / 2;
e.Graphics.DrawString("화성도시공사 화물차주차장 담당자", font, Brushes.Black, textX, e.MarginBounds.Top + 800);
}
}
}