473,379 Members | 1,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Modify textbox from class other than Form1

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)

Expand|Select|Wrap|Line Numbers
  1. public string SourceDir
  2.         {
  3.             get { return SourcePath.Text; }
  4.             set { SourcePath.Text = value; }
  5.         }
  6.  
I then have this method on a class called dirinfo.

Expand|Select|Wrap|Line Numbers
  1. public void dirreader(FolderBrowserDialog folderBrowserDialog, ListBox listBox)
  2.         {
  3.             folderBrowserDialog.ShowDialog();
  4.  
  5.             Form1.SourceDir = folderBrowserDialog.SelectedPath;
  6.  
  7.             listBox.Items.Clear();
  8.  
  9.             DirectoryInfo dir = new DirectoryInfo(folderBrowserDialog.SelectedPath);
  10.  
  11.             DirectoryInfo[] subdirectories = dir.GetDirectories();
  12.  
  13.             FileInfo[] directoryFiles = dir.GetFiles();
  14.  
  15.             foreach (FileInfo str in directoryFiles)
  16.             { listBox.Items.Add(str); }
  17.         }
  18.  
  19.  
This will not work, I get this

Error An object reference is required for the nonstatic field, method, or property 'Ras.Form1.SourceDir.get'
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
Expand|Select|Wrap|Line Numbers
  1. Form1 newform = new Form1();
  2. newform.SourceDir = folderBrowserDialog.SelectedPath;
  3.  
but unsurprisingly while it compiles, it does not show the path on the textbox.

I know i can make it work by putting
Expand|Select|Wrap|Line Numbers
  1. SourceDir = folderBrowserDialog.SelectedPath;
on the Form1 class, but I would like to learn how to do it without resorting to this.

Any ideas?

TIA
Oct 12 '07 #1
0 983

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Claudia Fong | last post by:
Hi, I have 2 forms. Form1 has a button which calls form2, but I need to know the value of the form1.textBox1.text. When I show form2, I try to use the code bellow: textBox1.Text =...
28
by: kfrost | last post by:
I know this is probably simple but I have a C# form and the class for the form is called sbaSynch. I have a textbox name txtServerName. I'm creating a class to manipulate XML functions so I...
2
by: leila | last post by:
I am developing an ASP.Net application for a client and they need to modify the page layout from within a form. like the way you edit a blog template in Blogger. what is the best approach to do...
4
by: Tom McLaughlin | last post by:
I have been working on projects in vb5 and I am now trying to get started with .net as you can see I am not doing very well. I have a program that has two forms. On form1 I have a TextBox1. From...
3
by: DotNetNewbie | last post by:
I am reading the book Teach Yourself Microsoft Visual Basic .Net 2003 in 21 Days. I am having trouble getting one of the exercises to work at the end of day 4. Exercises: 1. Create a new...
10
by: Rob | last post by:
Question : I want to create a read only TextBox that does not respond to any input from the keyboard, therefore I came up with the following derived class : Option Strict On Imports...
2
by: Benny | last post by:
Is there a way to trace exceptions and messages captured with the Enterprise Library to a custom destination like a text box or any other control? If not can anyone think of a way to "hack"...
7
by: Boki | last post by:
Hi All, I want to change WindowState of form1 from form2. I tried these two methods, but no luck on both. (1) Declare a public method: /* function of form1 */ public void...
5
by: =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?= | last post by:
I'm sorry, but I've read your code a couple of times and just don't see where the Form1 is initialized. Form1 also sounds like a class name, and this would be how you could do some form operations...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.