以下是打印窗体的源码(下面还用了窗体按数据量自动变形---上下)
因打出的分辩率是默认的,效果不太好,请问要改分辩率.......语句是怎么写...谢大家了
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace huixinERP
{
public partial class Print_SH : Form
{
public Print_SH()
{
InitializeComponent();
}
private void Print_Load(object sender, EventArgs e)
{
string sql11 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\My Documents\\huixinERP\\obj\\Release\\data\\path.mdb";
string selec11 = "SELECT 路径 from LJ";
OleDbConnection conn11 = new OleDbConnection(sql11);
OleDbDataAdapter dataa11 = new OleDbDataAdapter(selec11, conn11);
conn11.Open();
DataSet dataset21 = new DataSet();
dataa11.Fill(dataset21, "LJ");
conn11.Close();
path.DataBindings.Add("Text", dataset21, "LJ.路径");
string sql = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\My Documents\\huixinERP\\obj\\Release\\data\\path.mdb";
string sele = "SELECT * from Prints";
string sele1 = "SELECT 施工单号,印件名称,起止号码,单价,数量,提货单 from Prints";
string sele2 = "SELECT 施工单号,印件名称,起止号码,单价,数量 from Prints";
OleDbConnection conn = new OleDbConnection(sql);
OleDbDataAdapter dataa = new OleDbDataAdapter(sele, conn);
OleDbDataAdapter dataa1 = new OleDbDataAdapter(sele1, conn);
OleDbDataAdapter dataa2 = new OleDbDataAdapter(sele2, conn);
DataSet dataset1 = new DataSet();
DataSet dataset2 = new DataSet();
DataSet dataset3 = new DataSet();
conn.Open();
dataa.Fill(dataset1, "Prints");
dataa1.Fill(dataset2, "Prints");
dataa2.Fill(dataset3,"Prints");
dataGrid1.SetDataBinding(dataset3, "Prints");
conn.Close();
dataGrid1.RowHeadersVisible = false;
dataGrid1.CaptionVisible = false;
DWMC.DataBindings.Clear();
GDH.DataBindings.Clear();
RQs.DataBindings.Clear();
DWMC.DataBindings.Add("Text", dataset1, "Prints.单位名称");
GDH.DataBindings.Add("Text", dataset1, "Prints.提货单");
RQs.DataBindings.Add("Text", dataset1, "Prints.日期");
int a=Convert.ToInt32(dataset1.Tables["Prints"].Rows.Count.ToString());
if (a > 1)
{
a = (a - 1) *23;
int b = label13.Location.X;
int c = label13.Location.Y;
c += a;
Point poin = new Point(b, c);
label13.Location = poin;
b= label14.Location.X ;
c = label14.Location.Y;
c += a;
Point poin1 = new Point(b, c);
label14.Location = poin1;
b = label7.Location.X;
c = label7.Location.Y;
c += a;
Point poin2 = new Point(b, c);
label7.Location = poin2;
b = label8.Location.X;
c = label8.Location.Y;
c += a;
Point poin3 = new Point(b, c);
label8.Location = poin3;
int z = dataGrid1.Size.Height;
int y = dataGrid1.Size.Width;
z += a;
System.Drawing.Size siz = new Size(y,z);
this.dataGrid1.Size = siz;
int s =ClientSize.Height;
int w = ClientSize.Width;
s += a;
System.Drawing.Size siz1 = new Size(w, s);
this.ClientSize = siz1;
int r = Prin.Location.X;
int t = Prin.Location.Y;
t += a;
Point poins = new Point(r, t);
Prin.Location = poins;
}
}
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern long BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memoryImage;
private void CaptureScreen()
{
Graphics mygraphics = this.CreateGraphics();
Size s = this.Size;
memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
IntPtr dc1 = mygraphics.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
}
private void Prin_Click(object sender, EventArgs e)
{
Prin.Visible = false;
string sql1 = path.Text;
string sele = "UPDATE THBH SET 提货单号=" + Convert.ToInt32(Convert.ToInt32(GDH.Text) + 1);
OleDbConnection conn1 = new OleDbConnection(sql1);
conn1.Open();
OleDbCommand comm = new OleDbCommand(sele, conn1);
comm.ExecuteNonQuery();
conn1.Close();
CaptureScreen();
printDocument1.Print();
}
private void printDocument1_PrintPage_1(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
}
}
}