Tim Geiges <kernelsandirs@gmail.com> wrote:[color=blue]
> I am trying to open an image in a little image viewer I wrote(it has
> its own file explorer but I want it to also open from Windows Explorer)
>
>
> When I select an image from widows explorer and use "Open With"
> point it to my app, I can read the args[0] which contains the path to
> the file
> but I cannot pass the argument to another method to open the image
> window
>
> public string thefile = "";
>
> public static void Main(string[] args)
> {
> Application.Run(new MainForm());
> thefile = args[0].ToString();
> }
>
> My Documents\SharpDevelop Projects\imgbrowse\MainForm.cs(62,4): error
> CS0120: An object reference is required for the nonstatic field,
> method, or property 'imgbrowse.MainForm.thefile'
>
> how can I pass the value of args[0] from Main to my ImageView method?[/color]
Well, for one thing, Application.Run isn't going to return until your
form has been closed, which probably isn't what you want.
The easiest thing to do would be to make the MainForm constructor take
a string[] parameter, and pass the arguments to that:
[STAThread]
public static void Main(string[] args)
{
Application.Run (new MainForm(args));
}
Then in the constructor, deal with the arguments appropriately.
--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too