我想從其他類的類「Form1」調用方法。 這裏是我的代碼從其他類調用類方法不工作
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
MessageBox.Show("loaded");
orders.ObjectForScripting = new ScriptInterface();
}
private void webBrowser2_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { }
private void button1_Click_1(object sender, EventArgs e) { }
}
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public class ScriptInterface
{
public void callMe(string currid)
{
MessageBox.Show(currid);
// the following throws security error
Form1.webBrowser2.Navigate("http://www.mywebpage.com/client/index.php?id="+currid);
}
}
}
信息:我有2個WebBorwsers。我從webBrowser1獲取更新webBrowser2的事件。 我的問題是,我無法調用Form1以外的webbrowser2方法。
任何想法我可以如何解決這個問題?
將其標記爲'公共'而不是'私人'。 –