要在winform里用WebBrowser显示一个Web页,且需要向这个Web页传送数据。
我用了一个很笨的方法,简单如下:
webBrowser1.DocumentText = "<head><body>" +
"<table width='586' height='171' border='1' style='font-size:12px'>" +
"<tr><td width='98' height='23'>警示类别</td><td width='472'>"+strListInfo[0]+"</td></tr>" +
"</table></body></html>";
现在又有个新要求,必须要用css文件来改变样式,我就不知道怎么添加了。
谢谢了。
有更好的方法打开web页,并向这个web页传数据就更好了。
强调一点,是在winform中。
我用了一个很笨的方法,简单如下:
webBrowser1.DocumentText = "<head><body>" +
"<table width='586' height='171' border='1' style='font-size:12px'>" +
"<tr><td width='98' height='23'>警示类别</td><td width='472'>"+strListInfo[0]+"</td></tr>" +
"</table></body></html>";
现在又有个新要求,必须要用css文件来改变样式,我就不知道怎么添加了。
谢谢了。
有更好的方法打开web页,并向这个web页传数据就更好了。
强调一点,是在winform中。
例如:网站里面CSS都保存在特定的地方吗,给个地址,引用下
webBrowser1.DocumentText = " <head><link rel='stylesheet' type='text/css' href='Risk.css' /> <body>" +
" <table width='586' height='171' border='1' style='font-size:12px'>" +
" <tr> <td width='98' height='23'>警示类别 </td> <td width='472'>"+strListInfo[0]+" </td> </tr>" +
" </table> </body> </html>"; 这样没有用。
回答问题写个具体的代码吧。
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication108
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); webBrowser1.DocumentText = "<html><head>"
+ "<link href='" + AppDomain.CurrentDomain.BaseDirectory
+ "aa.css' rel='stylesheet' type='text/css'/></head>"
+ "<body>"
+ "<table width='586' height='171' border='1' style='font-size:12px'>"
+ " <tr class='XXX'>"
+ " <td width='98' height='23'>警示类别 </td> <td width='472'>"
+ " aaaaaaaaa"
+ " </td>"
+ " </tr>"
+ " </table></body></html>";
}
}
}