在Windows窗体应用程序中创建HTML [英] creating HTML in a windows forms application
问题描述
我有一个Windows窗体应用程序,该应用程序生成包含有效HTML的字符串.该字符串最终用于eBay列表中.我编写的方法只是将硬编码的字符串和传入的字符串变量连接在一起.它可以正常工作,但不灵活(如果我有两张照片怎么办?),不雅且丑陋.除了几个字符串和一个大锤,必须有更好的方法来创建HTML.
我度过了整个下午的谷歌搜索.我看过XDocument,HtmlDocument,DOM,StringBuilder,HtmlTextWriter,也许还有更多.
HtmlTextWriter看起来很有希望,但是它是ASP.Net的一部分,我无法弄清楚如何从Windows窗体应用程序获取它.而且,我怀疑是否很难解决它可能不是正确的解决方案.我应该只使用StringBuilder吗?
谁能指出我正确的方向?非常感谢.
I have a windows forms application which generates a string containing valid HTML. The string is eventually used in an eBay listing. The method I wrote just concatenates hardcoded strings and the incoming string variables. It works fine but is inflexible (what if I have two pictures?), inelegant, and ugly. There must be a better way to create HTML than just a couple of strings and a sledgehammer.
I''ve spent the afternoon Googling. I''ve looked at XDocument, HtmlDocument, DOM, StringBuilder, HtmlTextWriter, and probably more.
HtmlTextWriter seemed promising, but it is part of ASP.Net and I can''t figure out how to get to it from a windows forms app. And, I suspect if it is that hard to get to it might not be the right solution. Should I just use StringBuilder?
Can anyone point me in the right direction? Thanks much.
public static string MakeListingDescription(string title,string description,string pictureLocation1)
{
string doc = (
"
.
.
.
a mess of html
.
.
"
+ description +
"
.
.
a mess of html
.
.
"
+ pictureLocation1 +
"
.
.
more html
.
.
"
+ title +
"
.
.
last of the html
.
.
"
return doc;
}
推荐答案
我有个主意-似乎很愚蠢,但很简单,可能会有所帮助.为什么不将HTML文件包括在项目中,而是将WebBrowser控件放在Windows窗体上,然后再打开它? :-D
I got an idea - seems silly but simple and may help. Why don''t include your HTML file into your project, put a WebBrowser control on your windows form, and then open it? :-D
你到底想要什么?
如果要创建动态HTML页面,则可以有一个以TOKENS为值的HTML文件.读取WinApp中的HTML文件,并将所有标记替换为您的数据.
像这样的东西:
Hi,
what do you want exactly?
if you want to make a dynamic HTML page you can have a HTML file with the TOKENS as value. read the HTML file in you WinApp and replace all tokens with your data.
some thing like this:
<HTML>
<body>
<table>
<tr>
<td>FirstName:</td>
<td>@TOKEN_FirstName@</td>
</tr>
<tr>
<td>LastName:</td>
<td>@Token_LastName@</td>
</tr>
</table>
现在,您可以替换WinApp中的令牌并将其保存在新文件中.
(替换字符串可能会占用资源.因此,即使您使用StringBuilder,这种方式也可能会导致性能问题.)
希望对您有所帮助.
Now you can replace the tokens in your WinApp and saveitin a new file.
(Replacing strings can take resources. so this way might have performance problem. even if you use StringBuilder)
hope this can help.
这篇关于在Windows窗体应用程序中创建HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!