473,503 Members | 11,783 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reference external class from Windows Form

2 New Member
Hopefully this hasn't been asked already - apologies if so

I have a Windows Form running inside C# - built using the form designer

I've built a number of methods inside the form Events which I now want to strip out into External class files (in order to try and make the app a bit more architecturally correct so to speak).

To do this, I have created a new Project which I've added to the Solution.
I've managed to connect the class to the form by building the .cs file and then referencing the class in my form method - example reference:

ClearDetails cls = new ClearDetails();

So, if I have this right, I should be able to add my namespace to my form code, then specify the above code inside the Form Load event, then ultimately, the cls object created above should be available inside any event within the form?

However, this does not appear to be the case - the cls object is only available in the Form Load event?

My Class file contains a Public ClearDetails constructor along with a public method. The class file also uses the System.Windows.Forms namespace. I am using VS 2008 with Framework 3.5

If anyone could help or point me in the right direction, your help would be greatly appreciated

Many Thanks,
Dan
Apr 2 '10 #1
2 5342
tlhintoq
3,525 Recognized Expert Specialist
Its a matter of scope. In easy terms: A variable only exists between the { and }
If you give it life in the Load() {} then it dies at the end of the Load() {}
But if you give it life at the Class() {} then it doesn't die until the end of the class () {}

So move the creation of the variable up a little, but set its value in the load()

Expand|Select|Wrap|Line Numbers
  1.  
  2. namespace blahblah
  3. {
  4.    class  widget
  5.    {
  6.       ClearDetails myDetails; // Scope lifetime of the entire Widget class
  7.  
  8.       Form1_load
  9.       {
  10.            myDetails = new ClearDetails(); // assigned a value
  11.       }
  12.  
  13.    }
  14. }
  15.  
  16.  
Apr 2 '10 #2
danphillips1977
2 New Member
Many thanks tlhintoq

Understand. That all works a treat now
Apr 4 '10 #3

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

Similar topics

17
4178
by: Karl Irvin | last post by:
To use the Textstream object, I had to set a Reference to the Microsoft Scripting Runtime. This works good with A2000 Is the Scripting Runtime included with A2002 and A2003 so the Reference...
3
3154
by: Poewood | last post by:
Okay here are four classes for a pocket pc program: Input, fpositional, ComboBoxArray and TextBoxArray. The "input" class is the form. I use the fpositional class to handle most of the functions...
3
8565
by: Mochuelo | last post by:
Hi, In the constructor of a class, I am taking as a parameter the reference to a "bool", as in this code: ----------------------- public class TCP_synch_client { public string address...
1
19064
by: david | last post by:
I have a simple csharp form with a 'Go' button on it. This event launches a external exe successfully but the form color becomes white and does not repaint while that external program runs,...
3
2690
by: Gustavo L. Fabro | last post by:
Greetings! I'm a newbie in Visual C++ .NET (have programmed in Borland C++ and Builder for long) and I am trying to do a very simple thing, but I'm stuck. I created an (unmanaged) DLL project...
2
2564
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
2
2196
by: Jeff | last post by:
I'm getting an Object Reference error before I even run my app, and I'm not sure where to look to find the cause. I'd appreciate your help. When I open my Windows Application project, the...
5
3611
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As...
1
8328
by: Don | last post by:
I'm getting the following exception displayed in the task list at design time for my project: "Code generation for property 'Controls' failed. Error was: 'Object reference not set to an...
1
1598
by: JasonT | last post by:
Hi. I have created a dll in VC++ 08 that exports a CLR windows form class. I call into this dll from an external (closed source, third-party) application to instantiate the form and embed it into...
0
7193
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,...
0
7067
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...
0
7316
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...
1
6975
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...
0
5562
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,...
1
4992
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...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
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 ...

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.