代码之家  ›  专栏  ›  技术社区  ›  Imran Ali Khan

Visual Studio 2015社区报告查看器版本12使用C获取额外利润时出错#

  •  4
  • Imran Ali Khan  · 技术社区  · 7 年前

    我正在使用Visual Studio 2015 Community Report Viewer版本12在我的C项目中显示RDLC报告。 这是普通的A4纸报告

    它适用于Windows XP、Vista和Win 7客户端PC,但当相同的应用程序安装在Windows 10 64位上时,我会遇到如下问题

    正如你在上面的图片中看到的,有一些不必要的边距来自右边和底端,字体大小也减少了。但当我将报告导出到PDF时,生成的PDF中没有问题,它与我设计的报告相同。

    我试过什么:

    1. 我从安装了Microsoft Report Viewer 2015运行时 https://www.microsoft.com/en-us/download/details.aspx?内径=45496
    2. 已安装Microsoft SQL Server 2014功能包(用于SQL的系统CLR类型) 服务器2014)
    3. 尝试使用以下代码将RDLC直接导出到打印机

    打印类代码

    公共静态类 { 私有静态int m_currentpageindex; 私有静态ilist<stream>m_streams; 公共静态流CreateStream(字符串名称, 字符串文件扩展名,编码编码, 字符串mimetype,bool willseek) { stream stream=new memoryStream(); m_streams.add(流); 回流; } 公共静态无效导出(localreport,bool print=true,double-pagewightinches=8.27,double-pageheightinches=11.69,double-margintopinches=0.025,double-marginlefinches=0.025,double-marginrightinches=0.025,double-marginbottominches=0.025) { 字符串设备信息= @“<deveinfo><outpuformat>emf</outpuformat><pagewidth></pagewidth></pagewidth><pageheight></pageheight></pageheight></pageheight></pageheight></pageheight><<设备信息>><输出格式>><<pagewidth><><<<<<<<<<胃肠道nrightinches+“in</MarginRight><MarginBottom>”+“in</MarginBottom></deviceInfo>”; 警告[]警告; m_streams=新列表<stream>(); report.render(“图像”,deviceinfo,createstream, 发出警告); foreach(M_流中的流) 流.位置=0; 如果(打印) { _ mprint(_pagewightinches,_pageheightinches,_margintopinches,_marginleftinches,_marginrightinches,_marginbottominches); } report.releasesandboxappdomain(); } //printpageevents的处理程序 公共静态void _mprintpage(对象发送程序,printpageeventargs ev) metafile pageimage=新建 元文件(m_streams[m_currentpageindex]); //用打印机边距调整矩形区域。 Rectangle AdjustedRect=新矩形( ev.pagebounds.left-(int)ev.pagesettings.hardbarginx, ev.pagebounds.top-(int)ev.pagesettings.hardbarginy, ev.pagebounds.width,宽度, ev.pagebounds.height); //为报表绘制白色背景 ev.graphics.fillRectangle(brush.white,adjustedRect); //绘制报表内容 ev.graphics.drawimage(页面图像,调整数据); //准备下一页。确保我们没有到达终点。 m_currentpageindex++; ev.hasmorepages=(m_currentpageindex<m_streams.count); } 公共静态纸张尺寸计算纸张尺寸(双宽厘米,双高英寸) { int width=int.parse((math.round((widthincomm*0.393701)*100,0,middointrounding.awayFromZero)).toString()); int height=int.parse((math.round((heightincentimes*0.393701)*100,0,middointrounding.awayFromZero)).toString()); paperSize newSize=新paperSize(); newSize.rawkind=(int)paperkind.custom; newSize.width=宽度; newSize.height=高度; newSize.paperName=“信”; 返回新尺寸; } 公共静态无效打印(双页宽度英寸=8.27,双页高度英寸=11.69,双页边缘宽度英寸=0.025,双页边缘宽度英寸=0.025,双页边缘宽度英寸=0.025,双页边缘宽度英寸=0.025,双页边缘宽度英寸=0.025) { if(m_streams==null m_streams.count==0) 引发新异常(“错误:没有要打印的流”); printDocument printDoc=new printDocument(); PaperSize Required PaperSize=计算纸张尺寸(_pagewightinches*2.54,_pageheightinches*2.54); bool foundMatchingPaperSize=false; for(int index=0;index<printDoc.printerSettings.paperSizes.count;index++) { if(printDoc.printerSettings.paperSize[index].height==RequiredPaperSize.height&printDoc.printerSettings.paperSize[index].width==RequiredPaperSize.width) { printDoc.printerSettings.defaultPageSettings.paperSize=printDoc.printerSettings.paperSize[索引]; printDoc.defaultPageSettings.paperSize=printDoc.printerSettings.paperSize[索引]; FoundMatchingPaperSize=真; 断裂; } } 如果(!)printDoc.printerSettings.is有效) { 引发新异常(“错误:找不到默认打印机。”); } 其他的 { printDoc.printpage+=新的printpageEventHandler(_mprintpage); m_currentpageindex=0; printDoc.print(); } } 公共静态void mprinttoprinter(此本地报告) { _出口(报告); } 公共静态无效_mdisposeprint() { 如果(M3流!=空) { foreach(M_流中的流) Self(); m_streams=空; } } } < /代码>

    code on print button

    printviewer_pjobEntry=new printviewer();
    dataTable dt=new dataset1.maintabledataTable();
    dt.rows.add(“数据集的值”);
    _ pjobEntry._rptview.localreport.datasources.add(new reportdatasource(“dataset1”,dt));
    _ pjobEntry._rptview.localreport.reportEmbeddedResource=“wainfobussoln.printing.rptsaleinvoice02.rdlc”;
    _ pjobEntry.rptView.setDisplayMode(显示模式.printLayout);
    _ cWainfoPrintReport.Mexport(PjobEntry.RptView.localReport,true,8.27,11.69,0.25,0.25,0.28,0.25);
    < /代码> 
    
    

    但它也和上面描述的一样

    在我的电脑上运行的是Windows 10 64位的同一应用程序,但在部署了Windows 10 64位的客户电脑之后,该应用程序无法工作。

    在客户端PC.NET 4.0框架上,安装了SQL Server 2008和Windows 10 64位

    如何解决问题。

    它适用于Windows XP、Vista和Win 7客户端PC,但当相同的应用程序安装在Windows 10 64位上时,我会遇到如下问题

    Error In Windows 10

    正如你在上面的图片中看到的,有一些不必要的边距来自右边和底端,字体大小也减少了。但当我将报告导出到PDF时,生成的PDF和我设计的报告一样没有问题。

    我试过什么:

    1. 我从安装了Microsoft Report Viewer 2015运行时 https://www.microsoft.com/en-us/download/details.aspx?id=45496
    2. 已安装Microsoft SQL Server 2014功能包(用于SQL的系统CLR类型) 服务器2014)
    3. 尝试使用以下代码将RDLC直接导出到打印机

    打印类代码

    public static class _cWainfoPrintReport
        {
            private static int m_currentPageIndex;
            private static IList<Stream> m_streams;
            public static Stream CreateStream(string name,
            string fileNameExtension, Encoding encoding,
            string mimeType, bool willSeek)
            {
                Stream stream = new MemoryStream();
                m_streams.Add(stream);
                return stream;
            }
            public static void _mExport(LocalReport report, bool print = true, double _pageWightInches = 8.27, double _pageHeightInches = 11.69, double _MarginTopInches = 0.025, double _MarginLeftInches = 0.025, double _MarginRightInches = 0.025, double _MarginBottomInches = 0.025)
            {
                string deviceInfo =
                @"<DeviceInfo> <OutputFormat>EMF</OutputFormat> <PageWidth>" + _pageWightInches + "in</PageWidth> <PageHeight>" + _pageHeightInches + "in</PageHeight> <MarginTop>" + _MarginTopInches + "in</MarginTop> <MarginLeft>" + _MarginLeftInches + "in</MarginLeft> <MarginRight>" + _MarginRightInches + "in</MarginRight> <MarginBottom>" + _MarginBottomInches + "in</MarginBottom> </DeviceInfo>";
                Warning[] warnings;
                m_streams = new List<Stream>();
                report.Render("Image", deviceInfo, CreateStream,
                out warnings);
                foreach (Stream stream in m_streams)
                    stream.Position = 0;
                if (print)
                {
                    _mPrint(_pageWightInches, _pageHeightInches, _MarginTopInches, _MarginLeftInches, _MarginRightInches, _MarginBottomInches);
                }
                report.ReleaseSandboxAppDomain();
            }
            // Handler for PrintPageEvents
            public static void _mPrintPage(object sender, PrintPageEventArgs ev)
            {
                Metafile pageImage = new
                Metafile(m_streams[m_currentPageIndex]);
                // Adjust rectangular area with printer margins.
                Rectangle adjustedRect = new Rectangle(
                ev.PageBounds.Left - (int)ev.PageSettings.HardMarginX,
                ev.PageBounds.Top - (int)ev.PageSettings.HardMarginY,
                ev.PageBounds.Width,
                ev.PageBounds.Height);
                // Draw a white background for the report
                ev.Graphics.FillRectangle(Brushes.White, adjustedRect);
                // Draw the report content
                ev.Graphics.DrawImage(pageImage, adjustedRect);
                // Prepare for the next page. Make sure we haven't hit the end.
                m_currentPageIndex++;
                ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
            }
            public static PaperSize CalculatePaperSize(double WidthInCentimeters, double HeightInCentimetres)
            {
                int Width = int.Parse((Math.Round((WidthInCentimeters * 0.393701) * 100, 0, MidpointRounding.AwayFromZero)).ToString());
                int Height = int.Parse((Math.Round((HeightInCentimetres * 0.393701) * 100, 0, MidpointRounding.AwayFromZero)).ToString());
    
                PaperSize NewSize = new PaperSize();
                NewSize.RawKind = (int)PaperKind.Custom;
                NewSize.Width = Width;
                NewSize.Height = Height;
                NewSize.PaperName = "Letter";
    
                return NewSize;
    
            }
            public static void _mPrint(double _pageWightInches = 8.27, double _pageHeightInches = 11.69, double _MarginTopInches = 0.025, double _MarginLeftInches = 0.025, double _MarginRightInches = 0.025, double _MarginBottomInches = 0.025)
            {
                if (m_streams == null || m_streams.Count == 0)
                    throw new Exception("Error: no stream to print.");
                PrintDocument printDoc = new PrintDocument();
    
                PaperSize RequiredPaperSize = CalculatePaperSize(_pageWightInches * 2.54, _pageHeightInches * 2.54);
                bool FoundMatchingPaperSize = false;
                for (int index = 0; index < printDoc.PrinterSettings.PaperSizes.Count; index++)
                {
                    if (printDoc.PrinterSettings.PaperSizes[index].Height == RequiredPaperSize.Height && printDoc.PrinterSettings.PaperSizes[index].Width == RequiredPaperSize.Width)
                    {
                        printDoc.PrinterSettings.DefaultPageSettings.PaperSize = printDoc.PrinterSettings.PaperSizes[index];
                        printDoc.DefaultPageSettings.PaperSize = printDoc.PrinterSettings.PaperSizes[index];
                        FoundMatchingPaperSize = true;
                        break;
                    }
                }
    
    
                if (!printDoc.PrinterSettings.IsValid)
                {
                    throw new Exception("Error: cannot find the default printer.");
                }
                else
                {
    
                    printDoc.PrintPage += new PrintPageEventHandler(_mPrintPage);
                    m_currentPageIndex = 0;
                    printDoc.Print();
                }
            }
            public static void _mPrintToPrinter(this LocalReport report)
            {
                _mExport(report);
            }
            public static void _mDisposePrint()
            {
                if (m_streams != null)
                {
                    foreach (Stream stream in m_streams)
                        stream.Close();
                    m_streams = null;
                }
            }
        }
    

    打印按钮上的代码

    PrintViewer _PJobEntry = new PrintViewer();
    DataTable dt = new DataSet1.MainTableDataTable();
    dt.Rows.Add('vales for dataset');
    _PJobEntry._RptView.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dt));
    _PJobEntry._RptView.LocalReport.ReportEmbeddedResource = "WAINFOBUSSOLN.Printing.RptSaleInvoice02.rdlc";
    _PJobEntry._RptView.SetDisplayMode(DisplayMode.PrintLayout);
    _cWainfoPrintReport._mExport(_PJobEntry._RptView.LocalReport, true, 8.27, 11.69, 0.25, 0.25, 0.28, 0.25);
    

    但它也和上面描述的一样

    在我的电脑上运行的是Windows 10 64位的同一应用程序,但在部署了Windows 10 64位的客户电脑之后,该应用程序无法工作。

    如何解决。

    1 回复  |  直到 7 年前
        1
  •  2
  •   dj079    7 年前

    我不认为这个问题与安装的任何工具有任何关系,或者仅与Windows10 64位无关。

    相反,这是JDWENG&REZA Aghaei提到的DPI问题。更具体地说,高dpi设备。

    不确定您是否注意到了,但是您上传的图像都是不同的像素,低像素的图像显示报告的正确呈现。这可以支持由于高dpi导致的缩放问题。

    现在, 有很多关于这方面的文章、帖子和问题。但是,在向受害者提供某种正确的指导方面,最接近的是微软支持门户网站(Microsoft Support Portal)上的一个网站,它似乎没有为这种行为提供可能的解决方案(是的,复数)和解决办法(同样,复数)。

    您可以在此处找到本文: https://support.microsoft.com/en au/help/3025083/windows scaling-issues for high-dpi devices

    我相信,我在下面引用的解决方法暂时可以帮助您。

    < Buff行情>

    更改应用程序属性

    在资源管理器或“开始”菜单中,右键单击应用程序名称,选择“属性”,选择“兼容性”选项卡,然后选择“禁用高dpi设置时的显示缩放比例”复选框。

    注: 在Windows 10版本1703和更高版本的Windows中,“禁用高dpi显示缩放设置”选项的文本更改为“覆盖高dpi缩放行为”,缩放由:application执行。

    < /块引用> 另外,这是JDWENG&REZA Aghaei提到的DPI问题。更具体地说,高dpi设备。

    不确定您是否注意到了,但是您上传的图像都是不同的像素,低像素的图像显示报告的正确呈现。这可以支持由于高dpi导致的缩放问题。

    High-DPI_Scaling_Issue

    现在, 关于这方面有很多文章、帖子和问题。但是,在向受害者提供某种正确的指导方面,最接近的是微软支持门户网站(Microsoft Support Portal)上的一个网站,它似乎没有为这种行为提供可能的解决方案(是的,复数)和解决办法(同样,复数)。

    你可以在这里找到这篇文章: https://support.microsoft.com/en-au/help/3025083/windows-scaling-issues-for-high-dpi-devices

    我相信,我在下面引用的解决方法暂时可以帮助您。

    更改应用程序属性

    在资源管理器或“开始”菜单中,右键单击应用程序名称,选择“属性”,选择“兼容性”选项卡,然后选中“禁用高dpi设置时的显示比例”复选框。

    注: 在Windows 10版本1703和更高版本的Windows中,“高dpi设置时禁用显示缩放”选项的文本更改为覆盖高dpi缩放行为,缩放由:application执行。

    推荐文章