Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2007

Tip: Looking for answers? Try searching our database.

Linking objects between forms

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jed@auto-soft.co.za - 26 Feb 2007 08:17 GMT
How can i get access to textbox or an object in another form.I need
to insert a value from a textbox on form1 into a textbox on form2 but
cant get the textbox to appear in intellisense.I am a beginner still
learning C#  thanks.
DarkSoul - 26 Feb 2007 09:00 GMT
On Feb 26, 9:17 am, j...@auto-soft.co.za wrote:
>  How can i get access to textbox or an object in another form.I need
> to insert a value from a textbox on form1 into a textbox on form2 but
> cant get the textbox to appear in intellisense.I am a beginner still
> learning C#  thanks.

you can pass the values in the constructor of form2
jed@auto-soft.co.za - 26 Feb 2007 11:00 GMT
> On Feb 26, 9:17 am, j...@auto-soft.co.za wrote:
>
[quoted text clipped - 4 lines]
>
> you can pass the values in the constructor of form2

Please post example of how to do this. thank you
Pete Kane - 26 Feb 2007 11:07 GMT
> On Feb 26, 9:17 am, j...@auto-soft.co.za wrote:
>>  How can i get access to textbox or an object in another form.I need
[quoted text clipped - 3 lines]
>
> you can pass the values in the constructor of form2

to add to DarkSoul's reply you need to either pass form1 or the object
you wish to talk to in as a parameter to form2 or populate an existing
value in form2

public class Form1
{
    public string objectname = "";

    public somemethod()
    {
        // Create form2 here and pass a reference to Form1 to                 // the
constructor of form2
       
        Form2 frm = new Form2(this);

        // or populate a property of Form2 like this

        frm.somepropertyname = this; // you could also populate
        this property with whatever object you wish
        frm.Show();
    }
}

public class Form2
{
    public Form thecallingform;

    public Form2(Form frm)
    {
        this.thecallingform = frm;
    }

    public void anothermethod()
    {
        this.thecallingform.objectname = "foo";
    }
}

hope this helps
jed@auto-soft.co.za - 26 Feb 2007 10:58 GMT
Please post example of how to do this thank you
jed@auto-soft.co.za - 26 Feb 2007 11:32 GMT
Do you have to write all that just to take text from a textbox on
windowsform1 to another textbox on windowsform2.I have a button on
form1 when the user clicks the button i want to transfer the text.
jed@auto-soft.co.za - 26 Feb 2007 12:52 GMT
Sorry understand now thanks

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.