C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » .NET »

how to set a two rows in a single line while printing


Posted Date: 28 Jun 2008      Posted By: vidhya      Member Level: Gold     Points: 1   Responses: 0



hi,



i am print concept to print the dtagrid rows.....


i am using c# coding......


while taking the print i am getting output as(givn below)....



Pepsi 500ml £1.09


coke 500ml £1.09


Fanta 500ml £1.09


Sprite 500ml .99p

but my uotput should be like the given below......


Pepsi 500ml £1.09 coke 500ml £1.09


Fanta 500ml £1.09 Sprite 500ml .99p

tell me where i have to change my coding paart:

my coding is;

public class DataGridPrinter
{

private PrintDocument ThePrintDocument;
private DataTable TheTable;
private DataGridView TheDataGrid;

public int RowCount = 0; // current count of rows;
//private const int kVerticalCellLeeway = 10;

public int PageNumber = 1;
public ArrayList Lines = new ArrayList();

int PageWidth;
int PageHeight;
int TopMargin;
int BottomMargin;



public DataGridPrinter(DataGridView aGrid, PrintDocument aPrintDocument, DataTable aTable)
{
//
// TODO: Add constructor logic here
//

TheDataGrid = aGrid;
ThePrintDocument = aPrintDocument;
TheTable = aTable;
// TheTable.Columns.RemoveAt(3);

PageWidth = 350;
TopMargin = 30;
// PageWidth = ThePrintDocument.DefaultPageSettings.PaperSize.Width;
PageHeight = ThePrintDocument.DefaultPageSettings.PaperSize.Height;
//TopMargin = ThePrintDocument.DefaultPageSettings.Margins.Top;
//TopMargin = 100;
BottomMargin = ThePrintDocument.DefaultPageSettings.Margins.Bottom;


}

public void DrawHeader(Graphics g, int ff)
{
//SolidBrush ForeBrush = new SolidBrush(TheDataGrid.HeaderForeColor);
//SolidBrush BackBrush = new SolidBrush(TheDataGrid.HeaderBackColor);
//Pen TheLinePen = new Pen(TheDataGrid.GridLineColor, 1);
StringFormat cellformat = new StringFormat();
cellformat.Trimming = StringTrimming.EllipsisCharacter;

cellformat.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit | StringFormatFlags.NoClip;


int ht = ff + 2;

int columnwidth = 30;

int initialRowCount = RowCount;

// draw the table header
//float startxposition = TheDataGrid.Location.X;
float startxposition = 30;

RectangleF nextcellbounds = new RectangleF(0, 0, 0, 0);

RectangleF HeaderBounds = new RectangleF(0, 0, 0, 0);

HeaderBounds.X = TheDataGrid.Location.X;
HeaderBounds.Y = TheDataGrid.Location.Y + TopMargin + (RowCount - initialRowCount) * (TheDataGrid.Font.SizeInPoints + ht);
HeaderBounds.Height = TheDataGrid.Font.SizeInPoints + ht;
HeaderBounds.Width = PageWidth;

//g.FillRectangle(BackBrush, HeaderBounds);

for (int k = 0; k < TheTable.Columns.Count; k++)
{
string nextcolumn = TheTable.Columns[k].ToString();


//Command Line

//RectangleF cellbounds = new RectangleF(startxposition, TheDataGrid.Location.Y + TopMargin + (RowCount - initialRowCount) * (TheDataGrid.Font.SizeInPoints + kVerticalCellLeeway),
// columnwidth,
// TheDataGrid.HeaderFont.SizeInPoints + kVerticalCellLeeway);
//nextcellbounds = cellbounds;

//if (startxposition + columnwidth <= PageWidth)
//{
// g.DrawString(nextcolumn, TheDataGrid.HeaderFont, ForeBrush, cellbounds, cellformat);
//}

//startxposition = startxposition + columnwidth;

//Command LIne
}

//if (TheDataGrid.GridLineStyle != DataGridLineStyle.None)
//g.DrawLine(TheLinePen, TheDataGrid.Location.X, nextcellbounds.Bottom, PageWidth, nextcellbounds.Bottom);
}

public bool DrawRows(Graphics g, int fz)
{
int lastRowBottom = TopMargin;
int hh = fz + 60;
try
{
SolidBrush ForeBrush = new SolidBrush(TheDataGrid.ForeColor);
SolidBrush BackBrush = new SolidBrush(TheDataGrid.BackColor);
//SolidBrush AlternatingBackBrush = new SolidBrush(TheDataGrid.AlternatingBackColor);
//Pen TheLinePen = new Pen(TheDataGrid.GridLineColor, 1);
StringFormat cellformat = new StringFormat();
cellformat.Trimming = StringTrimming.EllipsisCharacter;
cellformat.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit;

//int columnwidth = PageWidth/TheTable.Columns.Count;
int columnwidth = (PageWidth / TheTable.Columns.Count);

//columnwidth = 100;

int initialRowCount = RowCount;

RectangleF RowBounds = new RectangleF(0, 0, 0, 0);

// draw vertical lines


Font printFont = new Font("Arial", fz);


// draw the rows of the table
for (int i = initialRowCount; i < TheTable.Rows.Count; i++)
{
DataRow dr = TheTable.Rows[i];

int startxposition = TheDataGrid.Location.X;
//startxposition = 20;

RowBounds.X = TheDataGrid.Location.X;
RowBounds.Y = TheDataGrid.Location.Y + TopMargin + ((RowCount - initialRowCount) + 1) * (TheDataGrid.Font.SizeInPoints + hh);
RowBounds.Height = TheDataGrid.Font.SizeInPoints + hh;
RowBounds.Width = PageWidth;
Lines.Add(RowBounds.Bottom);

if (i % 2 == 0)
{
g.FillRectangle(BackBrush, RowBounds);
}
else
{
//g.FillRectangle(AlternatingBackBrush, RowBounds);
}


for (int j = 0; j < TheTable.Columns.Count; j++)
{
RectangleF cellbounds = new RectangleF(startxposition,
TheDataGrid.Location.Y + TopMargin + ((RowCount - initialRowCount) + 1) * (TheDataGrid.Font.SizeInPoints + hh),
columnwidth,
TheDataGrid.Font.SizeInPoints + hh);
//200 + kVerticalCellLeeway);


if (startxposition + columnwidth <= PageWidth)
{
g.DrawString(dr[j].ToString(), printFont, ForeBrush, cellbounds, cellformat);
lastRowBottom = (int)cellbounds.Bottom;
}

startxposition = startxposition + columnwidth;
}

RowCount++;

if (RowCount + 1 * (TheDataGrid.Font.SizeInPoints + fz) > (PageHeight * PageNumber) - (BottomMargin + TopMargin))
{
DrawHorizontalLines(g, Lines);

//DrawVerticalGridLines(g, TheLinePen, columnwidth, lastRowBottom);
return true;
}


}

DrawHorizontalLines(g, Lines);
//DrawVerticalGridLines(g, TheLinePen, columnwidth, lastRowBottom);
return false;

}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
return false;
}

}

void DrawHorizontalLines(Graphics g, ArrayList lines)
{
//Pen TheLinePen = new Pen(TheDataGrid.GridLineColor, 1);

//if (TheDataGrid.GridLineStyle == DataGridLineStyle.None)
return;

for (int i = 0; i < lines.Count; i++)
{
// g.DrawLine(TheLinePen, TheDataGrid.Location.X, (float)lines[i], PageWidth, (float)lines[i]);
}
}

void DrawVerticalGridLines(Graphics g, Pen TheLinePen, int columnwidth, int bottom)
{
//if (TheDataGrid.GridLineStyle == DataGridLineStyle.None)
return;

for (int k = 0; k < TheTable.Columns.Count; k++)
{
g.DrawLine(TheLinePen, TheDataGrid.Location.X + k * columnwidth,
TheDataGrid.Location.Y + TopMargin,
TheDataGrid.Location.X + k * columnwidth,
bottom);
}
}


public bool DrawDataGrid(Graphics g, int ff)
{

try
{

DrawHeader(g, ff);
bool bContinue = DrawRows(g, ff);
return bContinue;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
return false;
}

}

}





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Post Reply
You must Sign In to post a response.
Next : How to Destroy object
Previous : PLz Give the answer
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use