|
Instead of e.Graphics.DrawImage, use Graphics.DrawString[^] and Graphics.DrawLine[^] to build your print image.
Printing screen elements very rarely works as well as you would hope: screens are ~ 72 dpi, even dot matrix printers are around 360!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
Thank you for your help ,i never use this method before can you show me an example about that.
|
|
|
|
|
Both the links lead to the overload list: look at the first overload method in each list, and it will have an example!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
thanks..
demonstration project in the form of a link is not at
|
|
|
|
|
Pardon? Do you mean "There are no demo projects at those links"?
If so, then you don't need projects: each override method has it's own sample code, unless you are looking at the Javascript examples, which will indeed not be there: click on the "C#" tab instead...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
As Griff said, this looks like a resolution problem (your printer has a higher DpiX, DpiY resolution than your screen), the best solution is to send the actual output elements (strings for text) to the printer.
The lazy way out is to send a bitmap at the right resolution. You can get the printer resolution from e.Graphics; you can get the screen resolution from:
Bitmap bm = new Bitmap(10,10);
Graphics g=Graphics.FromImage(bm);
int dpix=g.DpiX;
Therefore I would try this:
Bitmap bm = new Bitmap(10,10);
Graphics g=Graphics.FromImage(bm);
int dpix=g.DpiX;
int dpiy=g.DpiY;
bm.Dispose();
g=e.Graphics;
int w=this.Panel1.Width *g.DpiX/dpix;
int h=this.Panel1.Height*g.DpiY/dpiy;
bm = new Bitmap(w, h);
this.Panel1.DrawToBitmap(bm, new Rectangle(0, 0, w. h));
e.Graphics.DrawImageUnscaled(bm, 0, 0);
bm.Dispose();
Mind you, the bitmap will be larger than before, and printing will be slower. Printing the actual elements is the preferred way!
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
thank you for your reply i tried this code but problem remains.
<br />
Bitmap bm = new Bitmap(10, 10);<br />
<br />
<br />
Graphics g = Graphics.FromImage(bm);<br />
int dpix;<br />
dpix = Convert.ToInt16(g.DpiX);<br />
<br />
int dpiy;<br />
dpiy = Convert.ToInt16(g.DpiY);<br />
<br />
bm.Dispose();<br />
g = e.Graphics;<br />
int w;<br />
w = Convert.ToInt16(this.Panel1.Width * g.DpiX / dpix);<br />
int h;<br />
h = Convert.ToInt16(this.Panel1.Height * g.DpiY / dpiy);<br />
<br />
bm = new Bitmap(w, h);<br />
this.Panel1.DrawToBitmap(bm, new Rectangle(0, 0, w,h));<br />
e.Graphics.DrawImageUnscaled(bm, 0, 0);<br />
bm.Dispose();<br />
|
|
|
|
|
Sorry, my mistake. The diagnosis still is right, the solution isn't as
this.Panel1.DrawToBitmap(bm, new Rectangle(0, 0, w,h));
is upscaling the existing panel content to the right size, however it cannot improve the quality of the image that your panel is holding.
You really need to do one of two things:
1. send print element commands to the printer directly (DrawString stuff);
2. paint whatever it is you need to a Panel of the right size (same dpi upscaling to get its size), then draw that to the printer.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Thank you for your reply, i didnt use drawstring before you have any example codes or resources about that.
|
|
|
|
|
|
Do not have a way to do this way?
Bitmap bm = new Bitmap(10, 10);
Graphics g = Graphics.FromImage(bm);
int dpix;
dpix = Convert.ToInt16(g.DpiX);
int dpiy;
dpiy = Convert.ToInt16(g.DpiY);
bm.Dispose();
g = e.Graphics;
int w;
w = Convert.ToInt16(this.Panel1.Width * g.DpiX / dpix);
int h;
h = Convert.ToInt16(this.Panel1.Height * g.DpiY / dpiy);
bm = new Bitmap(w, h);
this.Panel1.DrawToBitmap(bm, new Rectangle(0, 0, w,h));
e.Graphics.DrawImageUnscaled(bm, 0, 0);
bm.Dispose();
|
|
|
|
|
ismail20 wrote: this.Panel1.DrawToBitmap(bm, new Rectangle(0, 0, w,h));
DrawToBitmap takes the available pixels and copies them to the destination, it does not know nor understand what it is your panel is showing, so it cannot improve how the text gets rendered. That is why I suggested you start with a bigger panel.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
|
Sorry, I can't do that.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
I use this code. but does not work. please tell my mistake
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Bitmap bm = new Bitmap(10, 10);
Graphics g = Graphics.FromImage(bm);
int dpix;
dpix = Convert.ToInt16(g.DpiX);
int dpiy;
dpiy = Convert.ToInt16(g.DpiY);
bm.Dispose();
g = e.Graphics;
int w;
w = Convert.ToInt16(this.Panel1.Width * g.DpiX / dpix);
int h;
h = Convert.ToInt16(this.Panel1.Height * g.DpiY / dpiy);
bm = new Bitmap(w, h);
this.Panel1.DrawToBitmap(bm, new Rectangle(0, 0, w, h));
e.Graphics.DrawImageUnscaled(bm, 0, 0);
bm.Dispose();
}
|
|
|
|
|
|
|
i set the panel's largest, still does not
|
|
|
|
|
help me please
|
|
|
|
|
So how is it related to C#?
|
|
|
|
|
Hi
I want to export Datagridview to excel. I have formatted my datagridview such that he negative values are shown as red, some values are bold and other formatting styles are applied. I want when I export it to Excel then it export with same formatted type.
Currently I Am using the below function to export. But unable to export with formatting.
private void exportAsExcel()
{
Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();
// creating new WorkBook within Excel application
Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);
// creating new Excelsheet in workbook
Microsoft.Office.Interop.Excel._Worksheet worksheet = null;
// see the excel sheet behind the program
//Funny
app.Visible = true;
// get the reference of first sheet. By default its name is Sheet1.
// store its reference to worksheet
try
{
//Fixed:(Microsoft.Office.Interop.Excel.Worksheet)
worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Sheets["Sheet1"];
worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.ActiveSheet;
// changing the name of active sheet
worksheet.Name = "Sheet1";
// storing header part in Excel
for (int i = 1; i < dgvDetails.Columns.Count + 1; i++)
{
worksheet.Cells[1, i] = dgvDetails.Columns[i - 1].HeaderText;
}
worksheet.get_Range("A1", "AZ1").Font.Bold = true;
worksheet.get_Range("A1", "A" + (dgvDetails.RowCount + 2).ToString()).Font.Bold = true;
// storing Each row and column value to excel sheet
for (int i = 0; i < dgvDetails.Rows.Count; i++)
{
for (int j = 0; j < dgvDetails.Columns.Count; j++)
{
worksheet.Cells[i + 2, j + 1] = dgvDetails.Rows[i].Cells[j].Value.ToString();
}
}
}
catch (System.Exception ex)
{
}
finally
{
app.Quit();
workbook = null;
app = null;
}
}
Thanks in advance
|
|
|
|
|
|
|
How to open a document using word automation and read the bookmark values in it?This has to be done as a function...input of the function will be the full path of the file to be opened and a list of bookmark names.
|
|
|
|
|
|