Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

c# global object

Posted on 2011-02-23
12
Medium Priority
?
433 Views
Last Modified: 2013-12-17
HI,

I create an object from form1, how can I refer it from form2?
Thanks,
JT
0
Comment
Question by:jtran007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34965099
Depending on what it is you are trying to achieve, you would probably just be better of passing the object to the second form in its constructor.
0
 
LVL 34

Expert Comment

by:it_saige
ID: 34965341
As long as the object is declared publically you could use:

form1.objectname in form2.

This is not in anyway the recommended way of accomplishing this.  Carls suggestion is more accurate from a programming standpoint.

-saige-
0
 

Author Comment

by:jtran007
ID: 34965388
Hi,

Thanks for your suggestion. Also I have a minor to ask. In the form1, I have define  
a textbox, right after the Initialization, I try copy the content of object to textbox.txt but
the compiler complains that textbox is not defined. I don't understand. Please help.
Thanks,
JT
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34965423
Right after initialization where? As long as it is after the call to InitializeComponent() it should be ok.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34965491
0
 

Author Comment

by:jtran007
ID: 34965553
Hi,

In the maiform, right after initialization.

Regards,
JT
0
 

Author Comment

by:jtran007
ID: 34965563
Hi,

In fact, after InitializeComponent();

Regards,
JT
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34965574
Can you post the code in question?
0
 

Author Comment

by:jtran007
ID: 34965708
Hi,

In the form:

 static void Setup()
{
   this.textbox1.Text = "testing";   <--- compiler complains
}
 public Initialization()
        {
            InitializeComponent();

            Setup();
         }


Regards,
JT
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 1000 total points
ID: 34965716
It will. The TextBox is an instance member of the Form, you cannot access it from a static method.
0
 

Author Comment

by:jtran007
ID: 34966650
HI,
Sorry I click the wrong button.
I want to credit this point to Carl.

Regards,
JT
0
 

Author Closing Comment

by:jtran007
ID: 34966655
Thanks,
JT
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question