C# winfom 水晶报表(For VS.NET2010)设置纵向打印,打印出的却是横向的,编程实现,勿手动设置
C# winfom 水晶报表(For VS.NET2010)设置纵向打印,打印出的却是横向的,请朋友们指点下.找出问题原因.
以编程方式实现,勿提供手动设置的方案.
代码如下:
private void 打印DToolStripMenuItem_Click(object sender, EventArgs e)
{
ReportDocument crReportDocument = new ReportDocument();
//Create an instance of a report
crReportDocument = new JcApp.Report.RptStock();// RptStock.rpt为水晶报表文件
//Use error handling in case an error occurs
try
{
//Set the printer name to print the report to. By default the sample
//report does not have a defult printer specified. This will tell the
//engine to use the specified printer to print the report. Print out
//a test page (from Printer properties) to get the correct value.
System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
string strPrintName = printDocument.PrinterSettings.PrinterName;
crReportDocument.PrintOptions.PrinterName = strPrintName;
//根据指定纸张格式名称设置纸张格式
Microsoft.Win32.RegistryKey rk;
if (!strPrintName.StartsWith(@"\\")) //本地打印机
rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Printers\\" + strPrintName + "\\DsDriver");
else //网络打印机
{
string[] p = strPrintName.Remove(0, 2).Split(new char[] { '\\' });
string path = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Providers\\LanMan Print Services\\Servers\\" + p[0] + "\\Printers\\" + p[1] + "\\DsDriver";
rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(path);
}
string[] papers = (string[])(rk.GetValue("printMediaSupported"));
//纸张格式名称与纸张格式id的键值对
System.Collections.Hashtable ht = new System.Collections.Hashtable();
for (int i = 0; i < papers.Length; i++)
{
ht.Add(papers[i], i);
}
//根据纸型名称在其名称列表中的索引,获取该索引在调用Get_PaperSizes后的size数组中的对应值
string strPageSizeName = "241二等分";//自定义纸张 宽度:2100mm 高度:1390mm
int[] sizes = PaperSizeGetter.Get_PaperSizes(strPrintName);
int paperSizeid = sizes[Convert.ToInt32(ht[strPageSizeName])];//sizes[this.listBoxPapers.SelectedIndex];
//将该size赋值给报表对象
crReportDocument.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)(paperSizeid);
crReportDocument.PrintToPrinter(1, true, 1, 1);
MessageBox.Show("打印完成!");
}
catch (Exception err)
{
MessageBox.Show(err.ToString());
}
}
//根据纸张名称获取其所在本地机上的PaperSize:调用的是PaperSizeGetter.Get_PaperSizes静态方法(是从水晶报表中reflect精简出来的,版权归原作者所有)
public class PaperSizeGetter
{
public static string OutputPort = String.Empty;
[DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int DeviceCapabilities(string pDevice, string pPort, short fwCapabilities, IntPtr pOutput, IntPtr pDevMode);
public static int[] Get_PaperSizes(string printer)
{
string text1 = printer;
int num1 = FastDeviceCapabilities(0x10, IntPtr.Zero, -1, text1);
if (num1 == -1)
{
return new int[0];
}
int num2 = Marshal.SystemDefaultCharSize * 0x40;
IntPtr ptr1 = Marshal.AllocCoTaskMem(num2 * num1);
FastDeviceCapabilities(0x10, ptr1, -1, text1);
IntPtr ptr2 = Marshal.AllocCoTaskMem(2 * num1);
FastDeviceCapabilities(2, ptr2, -1, text1);
IntPtr ptr3 = Marshal.AllocCoTaskMem(8 * num1);
FastDeviceCapabilities(3, ptr3, -1, text1);
int[] sizeArray1 = new int[num1];
for (int num3 = 0; num3 < num1; num3++)
{
string text2 = Marshal.PtrToStringAuto((IntPtr)(((long)ptr1) + (num2 * num3)), 0x40);
int num4 = text2.IndexOf('\0');
if (num4 > -1)
{
text2 = text2.Substring(0, num4);
}
short num5 = Marshal.ReadInt16((IntPtr)(((long)ptr2) + (num3 * 2)));
int num6 = Marshal.ReadInt32((IntPtr)(((long)ptr3) + (num3 * 8)));
int num7 = Marshal.ReadInt32((IntPtr)((((long)ptr3) + (num3 * 8)) + 4));
sizeArray1[num3] = System.Convert.ToInt32(num5);
}
Marshal.FreeCoTaskMem(ptr1);
Marshal.FreeCoTaskMem(ptr2);
Marshal.FreeCoTaskMem(ptr3);
return sizeArray1;
}
private static int FastDeviceCapabilities(short capability, IntPtr pointerToBuffer, int defaultValue, string printerName)
{
int num1 = DeviceCapabilities(printerName, OutputPort, capability, pointerToBuffer, IntPtr.Zero);
if (num1 == -1)
{
return defaultValue;
}
return num1;
}
}
相关推荐
frontend-design skills
frontend-design skills
用于计算系统状态的卡尔曼最优增益和最小均方误差(MMSE)估计研究(Matlab代码实现)
内容概要:本文围绕用于计算系统状态的卡尔曼最优增益和最小均方误差(MMSE)估计展开研究,深入探讨了卡尔曼滤波在动态系统状态估计中的核心作用。文章系统阐述了卡尔曼滤波的数学基础,包括状态空间模型的建立、先验与后验状态估计、协方差矩阵的递推更新,以及最优增益矩阵的推导过程,确保在高斯白噪声环境下实现对系统状态的最小均方误差估计。结合Matlab代码实现,完整展示了算法从理论建模到仿真实验的全流程,涵盖系统建模、噪声设置、滤波迭代、状态更新与误差分析等环节,并通过仿真实验验证了算法在噪声干扰下对系统真实状态的高精度跟踪能力。该研究为控制工程、导航系统、信号处理及自动化领域中的状态估计问题提供了坚实的理论依据与高效的数值实现方案。; 适合人群:具备一定控制理论、概率统计基础和Matlab编程能力,从事自动化、电子信息、航空航天、机器人、导航定位等相关领域的科研人员、工程技术人员及高校研究生。; 使用场景及目标:①掌握卡尔曼滤波的基本原理及其在状态估计中的数学推导过程;②学习如何利用Matlab实现卡尔曼滤波算法并进行系统仿真与性能评估;③应用于目标跟踪、传感器融合、惯性导航、故障诊断、时间序列预测等实际工程中的动态状态估计问题。; 阅读建议:建议读者结合文中提供的Matlab代码进行动手实践,通过调整系统模型参数、过程噪声与观测噪声强度,观察滤波效果的变化,深入理解卡尔曼增益的自适应调节机制与MMSE估计的收敛特性。同时可进一步拓展学习扩展卡尔曼滤波(EKF)、无迹卡尔曼滤波(UKF)等非线性滤波方法,以应对更复杂的非线性系统状态估计挑战。
政府科技管理者在推动区域科技成果转化过程中,如何解决成果供需匹配效率低的问题?.docx
政府科技管理者在推动区域科技成果转化过程中,如何解决成果供需匹配效率低的问题?
高校技术转移办公室人员如何提升成果转化服务效率?.docx
科易网基于行业知识库+行业大数据+科技资源要素+AI模型,以AI,赋能技术转移、成果转化、技术经理人培训、知识产权管理、区域产业分析与布局、地方科技招商、创新创业大赛等场景,推出科技创新领域的AI工具、场景化服务和数智化解决方案,推动科技创新与产业创新智能化发展。
国央企创新负责人如何利用平台实现技术需求的精准挖掘与匹配?.docx
科易网基于行业知识库+行业大数据+科技资源要素+AI模型,以AI,赋能技术转移、成果转化、技术经理人培训、知识产权管理、区域产业分析与布局、地方科技招商、创新创业大赛等场景,推出科技创新领域的AI工具、场景化服务和数智化解决方案,推动科技创新与产业创新智能化发展。


图表区

