标签: printdialog

使用Excel PrintOut方法时如何防止打印对话框

当我使用PrintOut方法将Worksheet对象打印到打印机时,即使我已设置DisplayAlerts = False,也会显示"打印"对话框(显示文件名,目标打印机,打印页面和取消按钮).下面的代码在Excel宏中工作,但如果我在VB或VB.Net应用程序中使用此代码(使用Excel对象需要引用更改),则会发生同样的情况.

Public Sub TestPrint()
Dim vSheet As Worksheet

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    Set vSheet = ActiveSheet
    vSheet.PrintOut Preview:=False

    Application.DisplayAlerts = True
    Application.ScreenUpdating = True

End Sub
Run Code Online (Sandbox Code Playgroud)

编辑:下面的答案更多地阐明了这一点(它可能是一个Windows对话框而不是Excel对话框),但没有回答我的问题.有谁知道如何防止它被显示?

编辑:谢谢你的额外研究,凯文.它看起来非常像我需要的东西.只是不确定我想盲目接受这样的API代码.是否有其他人对这些API调用有任何了解,并且他们正在做作者所声称的内容?

printing excel vba printdialog excel-vba

6
推荐指数
1
解决办法
2万
查看次数

在不同的UI线程中打印DocumentViewer的内容

在我的WPF应用程序中,我特别Window包含其中一个控件DocumentViewer.

打开并加载此窗口时,它会动态构建FixedDocument带有进度指示器的窗口,然后将其显示在DocumentViewer.它工作,并为了改善用户体验,我在自己的线程中运行此窗口,以便在构建文档时主应用程序窗口仍然响应.

基于此网页上的提示,我在一个新的线程中打开我的窗口,如下所示:

public void ShowDocumentViewerWindow(params object[] data) {
    var thread = new Thread(() => {
        var window = new MyDocumentViewerWindow(new MyObject(data));
        window.Closed += (s, a) => window.Dispatcher.InvokeShutdown();
        window.Show();
        System.Windows.Threading.Dispatcher.Run();
    });
    thread.SetApartmentState(ApartmentState.STA);
    thread.Start();
}
Run Code Online (Sandbox Code Playgroud)

到目前为止,我对这个设置很满意,但我刚遇到了一个问题.

MyDocumentViewerWindow 包含一个打印按钮,它引用内置的Print命令,以DocumentViewer为目标:

<Button Command="Print" CommandTarget="{Binding ElementName=MyDocumentViewer}">Print</Button>
Run Code Online (Sandbox Code Playgroud)

在我把窗口放在自己的线程之前,这很好用.但现在,当我点击它时,应用程序崩溃了.Visual Studio 2010将上面代码中的以下行突出显示为崩溃位置,并显示消息' 调用线程无法访问此对象,因为另一个线程拥有它.":

System.Windows.Threading.Dispatcher.Run();
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪如下所示:

at System.Windows.Threading.Dispatcher.VerifyAccess()
at MS.Internal.Printing.Win32PrintDialog.ShowDialog()
at System.Windows.Controls.PrintDialog.ShowDialog()
at System.Printing.PrintQueue.GatherDataFromPrintDialog(PrintDialog printDialog, XpsDocumentWriter&amp;amp; writer, PrintTicket&amp;amp; partialTrustPrintTicket, PrintQueue&amp;amp; partialTrustPrintQueue, Double&amp;amp; width, Double&amp;amp; height, String jobDescription)
at …
Run Code Online (Sandbox Code Playgroud)

printing wpf multithreading printdialog documentviewer

5
推荐指数
1
解决办法
5101
查看次数

使用光栅PTR打印机在java中打印文件

我有两个使用java打印的代码,如下所示:

第一个准则

for(int i = 0; i < files.length; i++) {
    String file = "C:\\images\\colour\\"+files[i].getName();
    String filename = file;
    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
    DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
    PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
    PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
    PrintService service = ServiceUI.printDialog(null, 200, 200, printService, defaultService, DocFlavor.INPUT_STREAM.GIF, pras);

    if (service != null) {
        DocPrintJob job = service.createPrintJob();

        PrintJobListener listener = new PrintJobAdapter() {
            public void printDataTransferCompleted(PrintJobEvent e) {
                System.exit(0);
            }
        };

        job.addPrintJobListener(listener);
        FileInputStream fis = new FileInputStream(filename);
        DocAttributeSet das = new …
Run Code Online (Sandbox Code Playgroud)

java pointers printdialog printers

5
推荐指数
1
解决办法
1165
查看次数

在matlab中打印多个数字

假设我在我的程序中生成了几个数字.我想让用户可以选择一次打印所有内容.我不想为每个页面显示打印对话框.因此,我只显示一次,仅显示第一个数字.这是我到目前为止提出的解决方案:

figHandles = get(0, 'Children');
for currFig = 1:length(figHandles)
    if(currFig == 1)
        printdlg(figHandles(currFig)); % Shows the print dialog for the first figure
    else
        print(figHandles(currFig)); % Does not show the print dialog and uses the latest printer selection
    end
end
Run Code Online (Sandbox Code Playgroud)

但问题是,如果用户取消第一个数字的打印,我无法抓住它并取消其他打印.我该怎么做?

matlab printdialog matlab-figure

5
推荐指数
1
解决办法
373
查看次数

如何更改win32窗口上的文本?

寻找从C#更改win32窗口上的文本的提示,技巧和搜索术语.

更具体地说,我正在尝试将打印对话框上的文本从"打印"更改为"确定",因为我使用对话框创建打印票而不进行任何打印.

如何找到对话框的窗口句柄?一旦我得到它,我将如何在窗体的子窗口中找到按钮?一旦我找到了,我将如何更改按钮上的文字?如何在显示对话框之前完成所有这些操作?

这里有一个类似的问题,但它指的是CodeProject的文章比需要的更复杂,并且花了我更长的时间来解析,而不是花在这上面.TIA.

.net c# winapi dialog printdialog

4
推荐指数
1
解决办法
3089
查看次数

Win32 PrintDlg,PrintDlgEx,Crashing和quirkiness

我的任务是解决以下问题:当调用PrintDlg()函数时,我的应用程序在64位机器上运行时崩溃.

在挖掘和拔毛之后,我决定最好的解决方案是用其更大的兄弟PrintDlgEx()替换PrintDlg()的原始调用.

这样做可以解决一个问题(它不再崩溃!),但会导致另一个问题.当我执行代码时,它不会显示打印对话框,只返回成功代码,并为我提供默认打印机的所有信息.我需要这个功能来显示标准的"打印设置"窗口,我不知道如何实现它.下面显示的是我试图用来显示对话框的示例值.

有什么想法吗?提前致谢.

//  Initialize the PRINTDLGEX structure.
pd2.lStructSize = sizeof(PRINTDLGEX);
pd2.hwndOwner = wnddata->wnd.hnd;
pd2.hDevMode = NULL;
pd2.hDevNames = NULL;
pd2.hDC = NULL;
pd2.Flags = PD_RETURNDC | PD_COLLATE;
pd2.Flags2 = 0;
pd2.ExclusionFlags = 0;
pd2.nPageRanges = 0;
pd2.nMaxPageRanges = 10;
pd2.lpPageRanges = NULL;
pd2.nMinPage = 1;
pd2.nMaxPage = 1000;
pd2.nCopies = 1;
pd2.hInstance = 0;
pd2.lpPrintTemplateName = NULL;
pd2.lpCallback = NULL;
pd2.nPropertyPages = 0;
pd2.lphPropertyPages = NULL;
pd2.nStartPage = START_PAGE_GENERAL;
pd2.dwResultAction = 0; …
Run Code Online (Sandbox Code Playgroud)

c printing winapi printdialog win32com

3
推荐指数
1
解决办法
2164
查看次数

通过代码更改PrintDialog中的打印机名称

我试图通过代码更改 PrintDialog 的选定打印机。我正在创建一个需要打印的图像,但图像的大小决定了应使用哪台打印机。我有我想要使用的打印机的名称,但我只是不知道在哪里更改该值。任何帮助都可以是 VB.NET 或 C# 形式。

谢谢。

.net printing printdialog

3
推荐指数
1
解决办法
8607
查看次数

在WPF中打印集合

有没有办法在WPF中打印内存集合或可变大小?

我正在使用以下代码打印ListView控件.但是当内容大于垂直滚动条接管并切割内容时.

 PrintDialog printDialog = new PrintDialog();
                printDialog.ShowDialog();

                printDialog.PrintVisual(lvDocumentSummary, "testing printing!");
Run Code Online (Sandbox Code Playgroud)

printing wpf printdialog

2
推荐指数
1
解决办法
8914
查看次数

使用Flow Document在PrintDialog上设置打印方向

只是想知道是否有办法在使用流文档的打印对话框上设置打印文档方向.

例如

var document = userControl.Content as FlowDocument;
var printDialog = new PrintDialog();
if (printDialog.ShowDialog() == true)
{
    var paginator = ((IDocumentPaginatorSource) document).DocumentPaginator;
    paginator.PageSize = new Size(userControl.Width, userControl.Height);

    //Set Orientation Landscape .....


    printDialog.PrintDocument(paginator, PrintDescription);
}
Run Code Online (Sandbox Code Playgroud)

c# wpf printdialog flowdocument

2
推荐指数
1
解决办法
6033
查看次数

PrintTicket提供程序无法绑定到打印机.Win32错误:打印机名称无效

我正在尝试在WPF应用程序中打印之前显示"打印"对话框.我正在使用此链接中的 Microsoft示例代码

// Create the print dialog object and set options
PrintDialog pDialog = new PrintDialog();
pDialog.PageRangeSelection = PageRangeSelection.AllPages;
pDialog.UserPageRangeEnabled = true;

// Display the dialog. This returns true if the user presses the Print button.
Nullable<Boolean> print = pDialog.ShowDialog();
Run Code Online (Sandbox Code Playgroud)

它在最后一行崩溃,但有以下异常:

PrintTicket提供程序无法绑定到打印机.Win32错误:打印机名称无效.

我试图寻找一个解决方案,人们建议的两个解决方案是安装打印机服务器功能,并切换到任何CPU版本,但这些都不适用于我的情况.

c# printing wpf winapi printdialog

2
推荐指数
1
解决办法
2567
查看次数