473,669 Members | 2,526 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Modify textbox from class other than Form1

1 New Member
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.Sour ceDir.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 996

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

Similar topics

5
30939
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 = formst.textBox1.Text; but this generates error -->
28
4314
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 added a class to project and it's named XmlApi(). In the XmlAPI() class I have simple code as following XmlAPI() { string str = "Some Text";
2
2135
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 that in ASP.net? is there a better (and more secure) way than setting permissions so they can edit the .ASPX files in a form? is there any way to use variables in that template instead of <asp:label ...> like the blogger templates?
4
1382
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 form2 I would like to write text to form1.TextBox1.text but this does not work in .net. What changes do I need to make this work. Jim
3
2178
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 multiple-form application that displays two forms when it starts, each with a text box. Add code to each text box’s TextChanged event (this is the
10
1587
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 System.Windows.Forms.TextBox Public Class DerivedTextBox Inherits TextBox
2
4317
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" something like this?
7
2559
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 active_this_form()
5
2353
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 in vb6, but not in .Net. This would explain why the messagebox works, as it is not instantiated, but called statically as you did in your code. I think you need this where your MsgBox is called: dim ui as New Form1() ui.txt_rec.Text =...
0
8466
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8384
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8896
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8810
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8590
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8659
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7410
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6211
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2798
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.