Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8776821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:08:45+00:00 2026-06-13T19:08:45+00:00

I’m trying to call methods from class Form1 from an other class. Here’s my

  • 0

I’m trying to call methods from class “Form1” from an other class.
Here’s my Code

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);
        }
    }

}

INFO: I have 2 WebBorwsers. I’m catching events from webBrowser1 for updating webBrowser2.
My problem is, that i cannot call the webbrowser2 methods outside from Form1.

Any Ideas how i can solve this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:08:46+00:00Added an answer on June 13, 2026 at 7:08 pm

    Your WebBrowser components are not static (this is a good thing), therefore you cannot refer to them directly off of Form1 as your code sample is attempting to do. You must obtain a reference to a Form1 instance and then you can call methods on them so long as they are marked public. Depending on your needs it is probably even better to just pass along a reference directly to your WebBrowser components

    Perhaps something like this:

    orders.ObjectForScripting = new ScriptInterface(this.webBrowser2);
    

    …

    public class ScriptInterface
    {
        private WebBrowser _browser;
    
        public ScriptInterface(WebBrowser browser)
        {
            _browser = browser;
        }
        public void callMe(string currid)
        {
            _browser.Navigate("http://www.mywebpage.com/client/index.php?id="+currid);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a text area in my form which accepts all possible characters from
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.