aditi
aditi

Reputation: 11

How to pass a variable from a windows form application to another non-form class, both in the same visual studio project?

I have a c# class that has a method operating on a vsriwble file path. This file path has to be selected by the user by browsing(file system) in Windows form . The selected path in form is to be passed to the class so that it works. I tried instantiating form in the class. But this didn't work. This is my code in the c# class. I've another winform code to browse file path. I need to pass that path from there in this code.

Upvotes: 1

Views: 155

Answers (1)

Dileep Namburu
Dileep Namburu

Reputation: 161

Here is the sample code.

var FD = new System.Windows.Forms.OpenFileDialog();
if (FD.ShowDialog() == System.Windows.Forms.DialogResult.OK) 
{
   string filepath= FD.FileName;
   //Here you can pass "filepath" variable to your method.
}

Thanks, Dileep.

Upvotes: 1

Related Questions