C# Question - accessing main form from outside files

JonnyBalls

Member
Apr 4, 2000
61
0
0
I have a generic windows project with a form.
I want to access members of that form from an outside file, like I want to get values of text fields or checkboxes, whatever...
how would I do this from an outside file since you can't use the "this"
 

imported_Pep

Junior Member
Mar 15, 2005
8
0
0
What do you mean by "an outside file"?

You could make your form a class which can be brought in as an include, or you could make the variables you want to access visible to the calling/inquiring program.
 

JonnyBalls

Member
Apr 4, 2000
61
0
0
oops, I mean another file within the project.
Lets say I have MainForm.cs where I just say string textValue=this.textbox.value
how would I be able to access that from a separate file in the same project?

I didn't think there were "includes" in c#
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Controls can be accessed by outside applications by locating the Windows Handle of the control and then operating it the same as you would from inside the program.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Enumerate the child windows from the parent window. All controls are a type of Window.

How you determine if it is the control you desire, it is based on what you are trying to accomplish.
 

KB

Diamond Member
Nov 8, 1999
5,406
389
126
Pass the MainForm (object that inherits from Form object) as an argument to the constructor of the outside file if it is a class, or as argument to a function.

In MainForm:
OutsideFile of = new OutsideFile(this);


Outside file class:
public class OutsideFile {
private MainForm _mf;
public OutsideFile(MainForm mf){
_mf = mf;

string textValue=_mf.textbox.value;
}
}