Click here to Skip to main content
15,910,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I'm very much new to .net application,
I'm doing a project where I want to get proper alignment at print time I'm not getting it.
Actually I want my print preview like many shopping mall bill(barcode,itemname,rate,quantity)all display exactly below
of all item here in my code I'm getting difference in all those item.I'm using winfrom and access database.
Please help me.
How to get alignment Rich textbox
Plz Help me i m eagerly Waiting for it even i did lot of googling........

Thanks in Advance
C#
private void Doc_PrintPage(object sender, PrintPageEventArgs e)
{
    //float tempgross = float.Parse(txtsubtotal.Text.Trim());
    Font font = new Font("Verdana", 10);
    Font font2 = new Font("Verdana", 40, FontStyle.Bold);

    float x = e.PageSettings.HardMarginX;
    float y = e.PageSettings.HardMarginY;

    float x1 = (e.PageSettings.Margins.Left = 10);
    float y1 = (e.PageSettings.Margins.Top = 60);

    string longline = "_________________________________";

    string clipinfo = "Date:" + System.DateTime.Now.ToShortDateString() + "" + "\n" + "Time   : " + System.DateTime.Now.ToShortTimeString() + "" + "   " + "Cashier :" + lbluserid.Text + "~" + userid1 + "";
    string Billheadinginfo = "SNo. "   + "Item Name" + "  "   + "Qty" + "  "   + "Rate" +   "    "    + "Amount";
    string Billvalue = "Total                       :                ";// +tempgross;
    string Thanks = "        THANK YOU VISIT AGAIN     ";

    float lineHeight = font.GetHeight(e.Graphics);

    string name = "Quotation";
    for (int i = 0; i < 1; i++)
    {
        e.Graphics.DrawString(name, font2, Brushes.Black, x, y);
        e.Graphics.DrawString("\n" + longline + "\n" + clipinfo + "\n" + longline + "\n" + Billheadinginfo + "\n" + longline + "\n" + richTextBox2.Text + longline + "\n" + Billvalue + "\n" + longline +  "\n" + "\n" + Thanks, font, Brushes.Black, x1, y1);
        y += lineHeight;
    }
    y += lineHeight;
}
Posted
Updated 4-Jan-12 18:28pm
v6
Comments
Richard MacCutchan 4-Jan-12 6:06am    
Please try explaining exactly what part of your alignment is failing, and maybe show some of the code that is not working.
rahul1431 4-Jan-12 7:42am    
private void Doc_PrintPage(object sender, PrintPageEventArgs e)
{

//float tempgross = float.Parse(txtsubtotal.Text.Trim());
Font font = new Font("Verdana", 10);
Font font2 = new Font("Verdana", 40, FontStyle.Bold);


float x = e.PageSettings.HardMarginX;
float y = e.PageSettings.HardMarginY;

float x1 = (e.PageSettings.Margins.Left = 10);
float y1 = (e.PageSettings.Margins.Top = 60);

string longline = "_________________________________";

string clipinfo = "Date:" + System.DateTime.Now.ToShortDateString() + "" + "\n" + "Time : " + System.DateTime.Now.ToShortTimeString() + "" + " " + "Cashier :" + lbluserid.Text + "~" + userid1 + "";
string Billheadinginfo = "SNo. " + "Item Name" + " " + "Qty" + " " + "Rate" + " " + "Amount";
string Billvalue = "Total : ";// +tempgross;
string Thanks = " THANK YOU VISIT AGAIN ";

float lineHeight = font.GetHeight(e.Graphics);

string name = "Quotation";
for (int i = 0; i < 1; i++)
{
e.Graphics.DrawString(name, font2, Brushes.Black, x, y);
e.Graphics.DrawString("\n" + longline + "\n" + clipinfo + "\n" + longline + "\n" + Billheadinginfo + "\n" + longline + "\n" + richTextBox2.Text + longline + "\n" + Billvalue + "\n" + longline + "\n" + "\n" + Thanks, font, Brushes.Black, x1, y1);
y += lineHeight;

}
y += lineHeight;
}
Richard MacCutchan 4-Jan-12 8:41am    
Added code to original question, although indenting seems to be broken.

1 solution

You still have not explained exactly what your problem is but I am guessing it's because you are using a proportional font rather than a fixed width type. Try something like "Courier New" and see if that works.
 
Share this answer
 
v2
Comments
fjdiewornncalwe 4-Jan-12 14:48pm    
typo fix... and a +5.
Richard MacCutchan 5-Jan-12 9:30am    
Thanks, for both.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900