2014-12-18 2 views
0

호텔 용 소프트웨어 응용 프로그램을 설계하고 있습니다. 감열 식 프린터에서 인보이스를 인쇄하고 DataGridView에서 특정 열을 인쇄하고 싶습니다. 나는 대부분의 작업을했지만 항목의 이름이 커지면 문자열이 인쇄 영역 밖으로 이동합니다.감열 프린터에서 특정 형식의 송장을 인쇄하는 방법

void pd_PrintPage(object sender, PrintPageEventArgs e) 
{ 
    Graphics graphic = e.Graphics; 
    Font font = new Font("Times New Roman", 8, FontStyle.Regular); 
    Font font2 = new Font("Times New Roman", 10, FontStyle.Bold); 
    float fontHeight = font.GetHeight(); 
    int startX = 10; 
    int startY = 10; 
    int offset = 40; 
    graphic.DrawString("Welcome to Jaipur Rajwada", new Font("Times New Roman", 10, FontStyle.Bold), new SolidBrush(Color.Black), startX, startY); 
    graphic.DrawString("Jaipur-Delhi Highway", new Font("Times New Roman", 9, FontStyle.Italic), new SolidBrush(Color.Black), startX + 15, startY + 18); 

    int z = 1; 
    foreach (DataGridViewRow dr in dataGridViewSell.Rows) 
    { 
     string discription = dr.Cells[0].FormattedValue.ToString().PadRight(10); 

     string price = string.Format("{0:c}", dr.Cells[2].FormattedValue.ToString()); 
     string quantity = dr.Cells[3].FormattedValue.ToString(); 
     string total = string.Format("{0:c}", dr.Cells[4].FormattedValue.ToString()); 
     string productline = z + " - " + discription + " - " + quantity + " - " + price + " - " + total; 
     graphic.DrawString(productline, font, new SolidBrush(Color.Black), startX - 3, startY + offset); 
     offset = offset + (int)fontHeight + 5; 
     z++; 
    } 
    offset = offset + 15; 
    graphic.DrawString("Total to Pay".PadRight(20) + String.Format("{0:c}", textBoxTotal.Text), font2, new SolidBrush(Color.Black), startX, startY + offset);  
} 

private void buttonPrint_Click(object sender, EventArgs e) 
{ 
    try 
    { 
     printReceipt(); 
    } 
    catch (Exception ex) 
    { 
     throw ex; 
    } 
} 
+0

나는 당신의 시도 캐치 당신은'MeasureString'를 사용하여 문자열의 길이를 계산하고 인쇄 영역을 초과하는 경우 일부 텍스트 줄 바꿈을 할 수있는, 그럼 조금 중복 .. – User2012384

+0

생각합니다. –

+0

가능한 [특정 형식으로 데이터를 인쇄하는 방법]의 중복. 그래서 그것이 인쇄하는 동안 mydesign을 사라지지 않습니다] (http://stackoverflow.com/questions/27523688/how-to-print-data-in-a-particular-format-so-that-it-doesnt-vanish- mydesign-whi) – Junaith

답변

0

수동으로 문자열 길이를 확인하고 텍스트 배치를 수행해야합니다.

예 :

string columnName = "..."; 
if(columnName.Length > 60) 
{ 
    graphic.DrawString(columnName_part1, new Font("Times New Roman", 10, FontStyle.Bold), new SolidBrush(Color.Black), startX, startY); 
    startY += 50; 
    graphic.DrawString(columnName_part2, new Font("Times New Roman", 10, FontStyle.Bold), new SolidBrush(Color.Black), startX, startY); 
} 
+0

솔루션에 감사하지만 실제로 작동하지 않습니다. 내가 원하는 것은 문자열 즉 Description의 첫 번째 부분 만 래핑하는 것입니다. 일반적으로 인보이스에 명시된대로 가격 및 수량을 결정합니다. –

+0

'Description' 열에 대해서만 고정 길이가 필요할 수 있으며 필요한 경우 간격을 둡니다. – opewix

+0

당신의 친절한 지원에 감사하지만 문자열 열 이름을 두 부분으로 나눌 수 없습니다. 즉 column_part1, column_part2 –

관련 문제