using System;
using SystemCollectionsGeneric;
using SystemComponentModel;
using SystemData;
using SystemDrawing;
using SystemText;
using SystemWindowsForms;
namespace WebBrowserTest
{
// This first namespace is required for the ComVisible attribute used on the ScriptManager class
using SystemRuntimeInteropServices;
using SystemWindowsForms;
// This is your form
public partial class Form1 : Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private SystemComponentModelIContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
componentsDispose();
}
baseDispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
thisWebBrowser1 = new SystemWindowsFormsWebBrowser();
thisSuspendLayout();
//
// WebBrowser1
//
thisWebBrowser1Dock = SystemWindowsFormsDockStyleFill;
thisWebBrowser1Location = new SystemDrawingPoint(0, 0);
thisWebBrowser1MinimumSize = new SystemDrawingSize(20, 20);
thisWebBrowser1Name = "WebBrowser1";
thisWebBrowser1Size = new SystemDrawingSize(544, 300);
thisWebBrowser1TabIndex = 0;
//
// Form1
//
thisAutoScaleDimensions = new SystemDrawingSizeF(6F, 12F);
thisAutoScaleMode = SystemWindowsFormsAutoScaleModeFont;
thisClientSize = new SystemDrawingSize(544, 300);
thisControlsAdd(thisWebBrowser1);
thisName = "Form1";
thisText = "Form1";
thisResumeLayout(false);
}
#endregion
private SystemWindowsFormsWebBrowser WebBrowser1;
// This nested class must be ComVisible for the JavaScript to be able to call it
[ComVisible(true)]
public class ScriptManager
{
// Variable to store the form of type Form1
private Form1 mForm;
// Constructor
public ScriptManager(Form1 form)
{
// Save the form so it can be referenced later
mForm = form;
}
// This method can be called from JavaScript
public void MethodToCallFromScript()
{
// Call a method on the form
mFormDoSomething();
}
// This method can also be called from JavaScript
public void AnotherMethod(string message)
{
MessageBoxShow(message);
}
}
// This method will be called by the other method (MethodToCallFromScript) that gets called by JavaScript
public void DoSomething()
{
// Indicate success
MessageBoxShow("I will close!");
thisClose();
}
// Constructor
public Form1()
{
// Boilerplate code
InitializeComponent();
// Set the WebBrowser to use an instance of the ScriptManager to handle method calls to C#
WebBrowser1ObjectForScripting = new ScriptManager(this);
// Create the webpage
WebBrowser1DocumentText = @"<html>
<head>
<title>Test</title>
</head>
<body>
<input type=""button"" value=""Go!"" onclick=""windowexternalMethodToCallFromScript();"" />
<br />
<input type=""button"" value=""Go Again!"" onclick=""windowexternalAnotherMethod('Hello');"" />
</body>
</html>";
}
}
}
如果你的异常处理添加在A1()中,那么异常处理之后仅仅返回到A1()的上层调用函数,也就是A()中。
由于A1()已经处理了异常,所以对于A()这一层而言,并没有异常发生,所以程序会继续,从而A2和A3将继续被执行。
如果你想中止A2和A3,那么你的异常处理必须写在调用它们的函数,也就是A()中。
以上就是关于c# 网站嵌套在winform里面 那么如何通过网站怎么关闭winform程序全部的内容,包括:c# 网站嵌套在winform里面 那么如何通过网站怎么关闭winform程序、C# winform程序 如何终止一个方法的执行 并返回主界面、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)