How do I reference a local resource in generated HTML in WinForms WebBrowser control?

前端 未结 5 667
天涯浪人
天涯浪人 2020-12-18 11:32

I\'m using a winforms webbrowser control to display some content in a windows forms app. I\'m using the DocumentText property to write the generated HTML. That part is wor

5条回答
  •  既然无缘
    2020-12-18 12:31

    Here's what we do, although I should mention that we use a custom web browser to remove such things as the ability to right-click and see the good old IE context menu:

    public class HtmlFormatter
    {
        /// 
        /// Indicator that this is a URI referencing the local
        /// file path.
        /// 
        public static readonly string FILE_URL_PREFIX = 
            "file://";
    
        /// 
        /// The path separator for HTML paths.
        /// 
        public const string PATH_SEPARATOR = "/";
    }
    
    
    // We need to add the proper paths to each image source
    // designation that match where they are being placed on disk.
    String html = HtmlFormatter.ReplaceImagePath(
        myHtml, 
        HtmlFormatter.FILE_URL_PREFIX + ApplicationPath.FullAppPath + 
        HtmlFormatter.PATH_SEPARATOR);
    

    Basically, you need to have an image path that has a file URI, e.g.

    
    

提交回复
热议问题