如何从控制台应用程序打开Windows窗体中的html文件 [英] How to open an html file in a windows form from a console application
本文介绍了如何从控制台应用程序打开Windows窗体中的html文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
StringBuilder buildHTML = new StringBuilder();
//Creating HTML File
buildHTML.Append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" +
"<html xmlns=\"http://www.w3.org/1999/xhtml\">" +
"<head>" +
"<center><H2 styele=\"color: #FF5C00;\">- Report</H2></center>" +
"<style>" +
"body { font-family: \"Calisto MT\", \"Bookman Old Style\", Bookman, \"Goudy Old Style\", Garamond, \"Hoefler Text\", \"Bitstream Charter\", Georgia, serif; }" +
"table { border-collapse: collapse; width: 100%; }" +
"th, td { padding: 0.25rem; text-align: left; border: 1px solid #000; }" +
"th{ background: #3B98E2; text-align: left; color: #fff; }" +
"tbody tr:hover { background: #A9D7FC; }" +
"</style>" +
"<title> ADAPT Report </title>" +
"</head><body> <table>" +
"<th>Sl.NO</th><th>Test</th><th>Description</th><th>Change during installation</th><th>Values Changed</th><th>Link</th>");
buildHTML.Append("</body></html>");
StreamWriter sw = new StreamWriter(@OutputFolder + "\\" + htmlName + ".html");
sw.WriteLine(buildHTML);
sw.Close();
Console.WriteLine("report created successfully");
var proc = new Process();
proc.StartInfo.FileName = @OutputFolder + "\\" + htmlName + ".html";
proc.Start();
proc.WaitForExit();
proc.Close();
我需要从我的控制台以Windows窗体的形式在浏览器中打开HTML页面应用程序,所以如果我关闭Windows应用程序浏览器和Windows应用程序自动关闭。
先谢谢
I need to open the HTML page in a browser in a windows form from my console application, so if i close the windows application the browser and the windows application close automatically.
Thanks in Advance
推荐答案
1)用winforms创建一个新项目
2)为能够显示html页面的winforms添加一个控件。你需要添加一些参考,我相信它被称为webcontrol或browsercontrol或其他东西。查看此处 [ ^ ]
3)在控制台项目中引用你的winforms项目并调用winforms对话框。
这样你就可以避免启动单独的浏览器进程等...
希望这会有所帮助。
1) create a new project with winforms
2) add a control to that winforms capable of showing html pages. You need to add some reference, I believe it's called webcontrol or browsercontrol or something. Look here[^]
3) reference your winforms project in the console project and call the winforms dialog.
That way you avoid starting up seperate browser processes etc...
Hope this helps.
这篇关于如何从控制台应用程序打开Windows窗体中的html文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文