user2659300
user2659300

Reputation: 3

How can I move this function into a Class

public string F03_veri_textbox(string veriadi3)
      {
          string Veritext;
          Veritext = webBrowser_sample.Document.GetElementById(veriadi3).GetAttribute("value");

          return Veritext;

      }

I have a webBrowser_sample object in Form1. I use this function to collect data from specific webpage. It is working properly.

I want to use this function from a class.

But when I try to move it, C# says "The name 'webBrowser_sample' does not exist in the current context".

If I define a new webBrowser_sample in the Class, it will create new webBrowser_sample object.

So I can't use it because I use this function to collect data while I am surfing this browser.

Upvotes: 0

Views: 61

Answers (1)

ps2goat
ps2goat

Reputation: 8485

Replace 'mytype' with the object type that webBrowser_sample is. You need to pass in a reference to the object, as in the code below. Another option would be to use an extension method.

public string F03_veri_textbox(string veriadi3, mytype browser)
  {
      string Veritext;
      Veritext = browser.Document.GetElementById(veriadi3).GetAttribute("value");

      return Veritext;

  }

Upvotes: 1

Related Questions