在Web浏览器控件中将背景图像加载到自定义Html页面

问题描述 投票:0回答:3

我有一个场景,当任何请求失败时,我需要导航到我自己的自定义html页面。我面临的问题是我有一个背景图像,我需要使用自定义html页面显示。

我已经实现了如下代码:

CustomHtmlDoc = "<html><head></head><body background=\"{0}\"; oncontextmenu='return false;'><br><br></br></br><hr><h4 style='font-family:Footlight MT Light;color:red;font-size:20px;'>" + "ErrorMessage" + "</h4><h4 style='font-family:Footlight MT Light;color:red;font-size:25px;'>Please Verify the Configured URL from Dashboard Configuration</h4> <hr></body></html>";
string CustomHtmlDocument = string.Format(CustomHtmlDoc,AppDomain.CurrentDomain.BaseDirectory + "AdministrationUIBrowser\\AdministrationUIBrowserFactory\\ErrorBackground.png");
WebBrowserControlView.DocumentText = CustomHtmlDocument;

当我尝试在本地运行场景时,我能够将错误页面作为背景。但在部署结束时,我只是得到空白屏幕,只有内容没有任何背景图像。我的是一个WPF应用程序。

html wpf-controls browser webbrowser-control
3个回答
0
投票

Windows窗体中的DocumentText实现不实现IMoniker,并且加载的文档将具有大约的基址:空白,因此您的页面无法找到背景图像。

您可以使用基本元素指定相对URL的基本位置,或实现URL名字对象。在http://www.codeproject.com/KB/miscctrl/csEXWB.aspx上有一个实现url名字对象的示例。在页面上搜索LoadHtmlIntoBrowser(string html,string sBaseUrl)。


0
投票

也许你可以使用Base64编码的图像。 Check this service out。我测试了它,它就像一个魅力。

希望能帮助到你。


0
投票

尝试100%确定(图像当前文件夹)

this.webBrowser1.DocumentText = 
    @"<b>This is an image:</b> <img src='" + 
    System.IO.Path.GetDirectoryName(Application.ExecutablePath) 
    +"/ErrorBackground.png'>";
© www.soinside.com 2019 - 2024. All rights reserved.