visual studio winform embed webview html

Install cefsharp and simple tutorial

The ie kernel used by the webbrowser that comes with vs does not support many things, so cefsharp is used here.

Access embedded resources

On the basis of this article

  1. Embed files in the front-end resource directory

        No need to follow the link,
                            insert image description here

Resources folder, if there is no such folder, you need to double-click Resources.resx,
                            insert image description here
add a resource arbitrarily (here it is assumed to be hh.png), save it, and the Resources folder will be there (you can also create it manually).
Put all the resources into the Resources folder, and change all the resource files to embedded resources. insert image description here
(Written here to find that the link seems to be better, it seems that it does not need to change the resources one by one to embedded)

  1. The return value type of the ProcessRequestAsync function of SchemeHandler
    ResourceSchemeHandler is not bool, and an error will be reported. Just correct it according to the error report. There are several return values, and I have not studied it specifically.

There is a problem with the resource loading of the ProcessRequestAsync function, which needs to be modified slightly, refer to the following

            Assembly ass = Assembly.GetExecutingAssembly();
            String resourcePath = ass.GetName().Name + ".Resources." + "hh.png";

            if (ass.GetManifestResourceInfo(resourcePath) != null)
            {
    
    
                Console.WriteLine(111);
                Stream stream = ass.GetManifestResourceStream(resourcePath);
            }
            else
            {
    
    
                Console.WriteLine(222);
            }

Everything else is the same as the tutorial.

Guess you like

Origin blog.csdn.net/baidu_38392815/article/details/122259889