Use the IE browser's COM components to display HTML files in the resource in WinForm

zhaozj2021-02-11  156

/// Use the IE browser's COM component to display the HTML file in the resource file in WinForm.

///

/// Here you have two:

/// 1. Call the COM component of IE

/// 2. Call Resource in the EXE file

/// The specific steps are as follows, please query help for specific usage:

/// 0. Add about.htm in the Project, the content is customized, the property is set to "Embedded Resource"

/// 1. Select the COM component "Microsot Web Browser" in the menu Tools-> Customize Toolbox

/// 2. In Solution Explorer-> Test (project name) -> References Right-click Microsoft.Mshtml (MSHTML.DLL)

/// 3. Place the browser new browser control on the WinForm form AxWebBrowser1

/// 4. Add a link button LinkAbout

/// 5. The key code is as follows:

Private void Linkabout_LinkClicked (Object Sender, System.Windows.Forms.LinkLabellinkClickedEventArgs E)

{

This.naVigate ("About: blank");

Mshtml.ihtmldocument2 doc = (mshtml.ihtmldocument2) this.axwebbrowser1.document;

String Abouthtml = this.getstringResource ("about.htm");

System.Diagnostics.debug.write (abouthtml);

Object [] obj = {abouthtml};

Doc.write (OBJ);

}

Private string getStringResource (String Name)

{

System.Reflection.Assembly asm = this.gettype (). Assmbly;

// list all resources in this file

System.Diagnostics.debug.writeline ("Found Resouces:");

FOREACH (String Rs in asm.getmanifestResourceNames ())

System.Diagnostics.debug.writeLine (RS);

Name = this.gettype (). Namespace "." Name;

System.io.Stream Strm = asm.getmanifestResourceStream (name);

// Convert to string with default system encoding.

Return new system.io.streamReader (STRM, System.Text.Encoding.default) .readToend ();

}

Private vid navigate (String URL)

{

Object flags = 0;

Object targetframe = string.empty;

Object poster = string.empty;

Object headers = String.empty;

This.axwebbrowser1.navigate (URL, Ref Flags, Ref TargetFrame, Ref PostData, Ref Headers);

}

///postscript:

/// Brother just learned C #, throwing bricks, I hope everyone will learn together, please tell me about MSN: Steeven_lee@citiz.net

/// There are still two places unclear:

/// 1. There is an article mentioned that RES: //test.exe/about.htm is not available.

/// 2. It will not be displayed when you click About.htm.

/// I still wrote a chat room brush screen, please leave a message, huh, huh

转载请注明原文地址:https://www.9cbs.com/read-5853.html

New Post(0)