c# printdialog 打印html,html - C# WebBrowser.ShowPrintDialog() not showing - Stack Overflow

I have this peculiar problem while wanting to print a html-report. The file itself is a normal local html file, located on my hard drive.

To do this, I have tried the following:

public static void PrintReport(string path)

{

WebBrowser wb = new WebBrowser();

wb.Navigate(path);

wb.ShowPrintDialog()

}

And I have this form with a button with the click event:

private void button1_Click(object sender, EventArgs e)

{

string path = @"D:\MyReport.html";

PrintReport(path);

}

This does absolutely nothing. Which is kind of strange... but things get stranger...

When editing the print function to do the following:

public static void PrintReport(string path)

{

WebBrowser wb = new WebBrowser();

wb.Navigate(path);

MessageBox.Show("TEST");

wb.ShowPrintDialog()

}

It works. Yes, only adding a MessageBox. The MessageBox is showing and after it comes the print dialog. I have also tried with Thread.Sleep(1000) instead, which doesn't work. Can anyone explain to me what's going on here? Why would a messagebox make any difference?

Can it be some kind of permission problem? I've reproduced this on both Windows 7 and 8, same thing. I made this small application with only the above code to isolate the problem. I am quite sure it works on windows XP though, since an older version of the application I'm working on runs on it. When trying to do this directly with the mshtml-dll instead I also get problems.

Any input or clarification is greatly appreciated!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值