C# winform WebBrowser控件的打印
具体代码如下:url = url.Replace("waytext:", "");
webBrowserFoodPrint.Size = new Size(220, 330);
webBrowserFoodPrint.Location = new Point(700, 50);
webBrowserFoodPrint.IsWebBrowserContextMenuEnabled = false;
webBrowserFoodPrint.AllowNavigation = true;
webBrowserFoodPrint.Visible = false;
webBrowserFoodPrint.SendToBack();
this.Controls.Add(webBrowserFoodPrint);
bool baseOnAppDir = ConfigurationManager.AppSettings["BaseOnAppDir"].ToUpper() == "TRUE";
string dataPathDrawPrint = "data\\map\\wayPrint.html";
string pathDrawPrint = "";
if (baseOnAppDir)
{
pathDrawPrint = AppDomain.CurrentDomain.BaseDirectory + dataPathDrawPrint;
}
else
{
pathDrawPrint = dataPathDrawPrint;
}
webBrowserFoodPrint.Navigate("file:///" + pathDrawPrint.Replace('\\', '/'));
string printTime = "打印时间: " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString();
webBrowserFoodPrint.ObjectForScripting = this;
webBrowserFoodPrint.Document.InvokeScript("update", new Object[] {url, printTime });
webBrowserFoodPrint.BringToFront();
webBrowserFoodPrint.Print();
e.Cancel = true;
return;
出现的问题是:界面刚打开初始化完成之后,第一次点击打印按钮运行这段代码,有完全运行这段代码(已调试,请不要回答调试看看是不是没跑),可是并没执行打印。然后重新点击打印,依然是跑这段代码,(已监视各个变量,全部和第一次点击时的一样),此时能够打印。每次都一样,界面刚初始化完成打开后总不能成功打印。点击第二次按钮之后就没有问题。而有些模块一样用这段代码(路径参数不一样而已),却没有发生这个问题。请问这是什么原因。 如何解决 --------------------编程问答-------------------- 把生成顺序改改看吧。可能第一次webBrowserFoodPrint还没加载进去。
补充:.NET技术 , C#