I'm still learning C# and this is really annoying me.
I need to modify the contents of a text box on a windows program.
(Using windows app template on VS 2005)
I have created a property on Form1 (SourcePath is a textbox)
I then have this method on a class called dirinfo.
This will not work, I get this
The thing is that I don't know what the instance for Form1, as far as I can tell there does not appear to an instance of Form1, which does not sound right.
I tried creating an instance of Form1, substituted bold line by this
but unsurprisingly while it compiles, it does not show the path on the textbox.
I know i can make it work by putting
on the Form1 class, but I would like to learn how to do it without resorting to this.
Any ideas?
TIA
I need to modify the contents of a text box on a windows program.
(Using windows app template on VS 2005)
I have created a property on Form1 (SourcePath is a textbox)
Code:
public string SourceDir
{
get { return SourcePath.Text; }
set { SourcePath.Text = value; }
}
Code:
public void dirreader(FolderBrowserDialog folderBrowserDialog, ListBox listBox)
{
folderBrowserDialog.ShowDialog();
[B] Form1.SourceDir = folderBrowserDialog.SelectedPath;[/B]
listBox.Items.Clear();
DirectoryInfo dir = new DirectoryInfo(folderBrowserDialog.SelectedPath);
DirectoryInfo[] subdirectories = dir.GetDirectories();
FileInfo[] directoryFiles = dir.GetFiles();
foreach (FileInfo str in directoryFiles)
{ listBox.Items.Add(str); }
}
Error An object reference is required for the nonstatic field, method, or property 'Ras.Form1.Sour ceDir.get'
I tried creating an instance of Form1, substituted bold line by this
Code:
Form1 newform = new Form1(); newform.SourceDir = folderBrowserDialog.SelectedPath;
I know i can make it work by putting
Code:
SourceDir = folderBrowserDialog.SelectedPath;
Any ideas?
TIA