📄 reportformsprint.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace WindowsApplication3
{
/// <summary>
/// ReportFormsPrint 的摘要说明。
/// </summary>
public class ReportFormsPrint : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.PrintPreviewControl printPreviewControl1;
private System.Windows.Forms.PageSetupDialog PrintConfig;
private System.Drawing.Printing.PrintDocument PrintMachine;
private float fontSize = 9;
/// <summary>
/// 总页数
/// </summary>
int PageCount = 0;
int CurrentPage = 1;
/// <summary>
/// 开始的
/// </summary>
int StartIndex = 0;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public ReportFormsPrint()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.printPreviewControl1 = new System.Windows.Forms.PrintPreviewControl();
this.PrintMachine = new System.Drawing.Printing.PrintDocument();
this.PrintConfig = new System.Windows.Forms.PageSetupDialog();
this.SuspendLayout();
//
// button2
//
this.button2.Location = new System.Drawing.Point(712, 528);
this.button2.Name = "button2";
this.button2.TabIndex = 11;
this.button2.Text = "打印";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(616, 528);
this.button1.Name = "button1";
this.button1.TabIndex = 10;
this.button1.Text = "打印设置";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// comboBox1
//
this.comboBox1.Items.AddRange(new object[] {
"200%",
"150%",
"100%",
"75%",
"50%",
"30%",
"25%"});
this.comboBox1.Location = new System.Drawing.Point(512, 528);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(88, 20);
this.comboBox1.TabIndex = 9;
this.comboBox1.Text = "预览比例";
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// printPreviewControl1
//
this.printPreviewControl1.AutoZoom = false;
this.printPreviewControl1.Document = this.PrintMachine;
this.printPreviewControl1.Location = new System.Drawing.Point(16, 16);
this.printPreviewControl1.Name = "printPreviewControl1";
this.printPreviewControl1.Rows = 2;
this.printPreviewControl1.Size = new System.Drawing.Size(784, 504);
this.printPreviewControl1.TabIndex = 8;
this.printPreviewControl1.Zoom = 0.5;
this.printPreviewControl1.Click += new System.EventHandler(this.printPreviewControl1_Click);
//
// PrintMachine
//
this.PrintMachine.BeginPrint += new System.Drawing.Printing.PrintEventHandler(this.PrintMachine_BeginPrint);
this.PrintMachine.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.PrintMachine_PrintPage);
//
// PrintConfig
//
this.PrintConfig.Document = this.PrintMachine;
this.PrintConfig.ShowHelp = true;
//
// ReportFormsPrint
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(802, 559);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.printPreviewControl1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "ReportFormsPrint";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "打印报表";
this.Load += new System.EventHandler(this.ReportFormsPrint_Load);
this.ResumeLayout(false);
}
#endregion
private void PrintMachine_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Font firstLineFont = new Font("宋体",fontSize+9,System.Drawing.FontStyle.Bold);
Pen blackPen = new Pen( Color.Black , 1 );
if( ReportForms.hexiang == false )
{
e.Graphics.DrawString("学历查询系统报表",new Font("宋体",fontSize+15,System.Drawing.FontStyle.Bold),Brushes.Black,250,50);
e.Graphics.DrawLine( new Pen( Color.Black,3),0,100,820,100 );
int startX = 65;
int startY = 165;
//画表列名
for( int k = 0 ; k < 7 ; k++ )
{
int columnY = 135 ;
Rectangle temp = new Rectangle( startX,columnY,100,30 );
e.Graphics.DrawRectangle( blackPen ,temp );
if ( k < ReportForms.GetSelect( ).Count )
{
e.Graphics.DrawString( ReportForms.GetSelect( )[k].ToString( ),new Font("宋体",fontSize + 4,System.Drawing.FontStyle.Bold),Brushes.Black,startX + 5 ,columnY + 10 );
}
startX += 100;
}
startX = 65;
//画表格
int tempIndex = StartIndex;
int count = QueryByNewData.printList.Items.Count ;
for ( int j = 0 ; j < 32 ; j ++ )
{
ListViewItem lvi;
try
{
lvi = QueryByNewData.printList.Items[tempIndex];
}
catch
{
lvi = null;
}
for( int i = 0 ; i < 7 ; i++ )
{
Rectangle temp = new Rectangle( startX,startY,100,30 );
e.Graphics.DrawRectangle( blackPen ,temp );
if ( i < ReportForms.GetSelect( ).Count && count > j)
{
if ( lvi != null )
{
e.Graphics.DrawString( GetString(ReportForms.GetSelect( )[i].ToString( ),lvi),new Font("宋体",fontSize - 1,System.Drawing.FontStyle.Regular),Brushes.Black,startX + 5 ,startY + 10 );
}
}
startX += 100;
}
startX = 65;
startY += 30;
tempIndex++;
}
if ( PageCount > CurrentPage )
{
CurrentPage++;
StartIndex = StartIndex + 32;
e.HasMorePages = true;
}
else
{
e.HasMorePages = false;
}
}
else //对大于8行的处理
{
e.Graphics.DrawString("学历查询系统报表",new Font("宋体",fontSize+15,System.Drawing.FontStyle.Bold),Brushes.Black,480,20);
e.Graphics.DrawLine( new Pen( Color.Black,3),0,60,1500,60 );
int startY = 100;
//画表列名
for( int k = 0 ; k < 15 ; k++ )
{
int columnY = 80 ;
if ( k == 0 )
{
Rectangle temp = new Rectangle( 15,columnY,40,20 );
e.Graphics.DrawRectangle( blackPen ,temp );
e.Graphics.DrawString( "姓名",new Font("宋体",fontSize,System.Drawing.FontStyle.Bold),Brushes.Black,18 ,columnY + 5 );
}
if ( k == 1 )
{
Rectangle temp = new Rectangle( 55,columnY,30,20 );
e.Graphics.DrawRectangle( blackPen ,temp );
e.Graphics.DrawString( "性别",new Font("宋体",fontSize,System.Drawing.FontStyle.Bold),Brushes.Black,58 ,columnY + 5 );
}
if ( k == 2 )
{
Rectangle temp = new Rectangle( 85,columnY,60,20 );
e.Graphics.DrawRectangle( blackPen ,temp );
e.Graphics.DrawString( "出生年月",new Font("宋体",fontSize,System.Drawing.FontStyle.Bold),Brushes.Black,88 ,columnY + 5 );
}
if ( k == 3 )
{
Rectangle temp = new Rectangle( 145,columnY,60,20 );
e.Graphics.DrawRectangle( blackPen ,temp );
e.Graphics.DrawString( "层次",new Font("宋体",fontSize,System.Drawing.FontStyle.Bold),Brushes.Black,148 ,columnY + 5 );
}
if ( k == 4 )
{
Rectangle temp = new Rectangle( 205,columnY,70,20 );
e.Graphics.DrawRectangle( blackPen ,temp );
e.Graphics.DrawString( "学历类型",new Font("宋体",fontSize,System.Drawing.FontStyle.Bold),Brushes.Black,208 ,columnY + 5 );
}
if ( k == 5 )
{
Rectangle temp = new Rectangle( 275,columnY,30,20 );
e.Graphics.DrawRectangle( blackPen ,temp );
e.Graphics.DrawString( "学制",new Font("宋体",fontSize,System.Drawing.FontStyle.Bold),Brushes.Black,278 ,columnY + 5 );
}
if ( k == 6 )
{
Rectangle temp = new Rectangle( 305,columnY,70,20 );
e.Graphics.DrawRectangle( blackPen ,temp );
e.Graphics.DrawString( "毕业结论",new Font("宋体",fontSize,System.Drawing.FontStyle.Bold),Brushes.Black,308 ,columnY + 5 );
}
if ( k == 7 )
{
Rectangle temp = new Rectangle( 375,columnY,70,20 );
e.Graphics.DrawRectangle( blackPen ,temp );
e.Graphics.DrawString( "入学日期",new Font("宋体",fontSize,System.Drawing.FontStyle.Bold),Brushes.Black,378 ,columnY + 5 );
}
if ( k == 8 )
{
Rectangle temp = new Rectangle( 445,columnY,70,20 );
e.Graphics.DrawRectangle( blackPen ,temp );
e.Graphics.DrawString( "毕业时间",new Font("宋体",fontSize,System.Drawing.FontStyle.Bold),Brushes.Black,448 ,columnY + 5 );
}
if ( k == 9 )
{
Rectangle temp = new Rectangle( 515,columnY,70,20 );
e.Graphics.DrawRectangle( blackPen ,temp );
e.Graphics.DrawString( "录入人员",new Font("宋体",fontSize,System.Drawing.FontStyle.Bold),Brushes.Black,518 ,columnY + 5 );
}
if ( k == 10 )
{
Rectangle temp = new Rectangle( 585,columnY,70,20 );
e.Graphics.DrawRectangle( blackPen ,temp );
e.Graphics.DrawString( "录入时间",new Font("宋体",fontSize,System.Drawing.FontStyle.Bold),Brushes.Black,588 ,columnY + 5 );
}
if ( k == 11 )
{
Rectangle temp = new Rectangle( 655,columnY,70,20 );
e.Graphics.DrawRectangle( blackPen ,temp );
e.Graphics.DrawString( "审核结果",new Font("宋体",fontSize,System.Drawing.FontStyle.Bold),Brushes.Black,658 ,columnY + 5 );
}
if ( k == 12 )
{
Rectangle temp = new Rectangle( 725,columnY,120,20 );
e.Graphics.DrawRectangle( blackPen ,temp );
e.Graphics.DrawString( "专业名称",new Font("宋体",fontSize,System.Drawing.FontStyle.Bold),Brushes.Black,728 ,columnY + 5 );
}
if ( k == 13 )
{
Rectangle temp = new Rectangle( 845,columnY,120,20 );
e.Graphics.DrawRectangle( blackPen ,temp );
e.Graphics.DrawString( "院校名称",new Font("宋体",fontSize,System.Drawing.FontStyle.Bold),Brushes.Black,848 ,columnY + 5 );
}
if( k == 14 )
{
Rectangle temp = new Rectangle( 965,columnY,140,20 );
e.Graphics.DrawRectangle( blackPen ,temp );
e.Graphics.DrawString( "证书编号",new Font("宋体",fontSize,System.Drawing.FontStyle.Bold),Brushes.Black,968 ,columnY + 5 );
}
}
int tempIndex = StartIndex;
int count = QueryByNewData.printList.Items.Count ;
for ( int j = 0 ; j < 34 ; j ++ )
{
ListViewItem lvi;
try
{
lvi = QueryByNewData.printList.Items[tempIndex];
}
catch
{
lvi = null;
}
for( int i = 0 ; i < 15 ; i++ )
{
if ( i == 0 )
{
Rectangle temp = new Rectangle( 15,startY,40,20 );
e.Graphics.DrawRectangle( blackPen ,temp );
if ( i < ReportForms.GetSelect( ).Count && count > j)
{
if( lvi != null )
{
e.Graphics.DrawString( GetString("姓名",lvi),new Font("宋体",fontSize-2,System.Drawing.FontStyle.Regular),Brushes.Black,17 ,startY + 5 );
}
}
}
if ( i == 1 )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -