473,569 Members | 2,762 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 5358
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
4186
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 won't be broken when my app is opened with those versions. Also is the Scripting Runtime included as part of the A2000 Runtime Engine which some of...
3
3160
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 for the objects on the form, in addition the The objects are created in the fpositional class and affixed to the Input form through the fpositional...
3
8607
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 =""; public int port =0;
1
19073
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, usually about 10 seconds. I tried creating a thread in seperate class to run that process instead on running it from main thread. This successfully...
3
2700
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 with a sample function, and tried to call it from a ".NET Forms" project. All I get are "Unresolved External" errors from the Linker!
2
2572
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 good while and I'm getting really frustrated now! My problem is this - my custom controls periodically disappear from my
2
2204
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 following Microsoft Development Environment error message displays: "Object reference not set to an instance of an object." Then when I access the...
5
3612
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 New System.Diagnostics.Process 'p.Start(MDEPDirStr & "macrun.exe", sPPTOut) p.Start("C:\WINDOWS\SYSTEM32\CALC.EXE")...
1
8347
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 instance of an object.'" I've traced the problem to a custom control I created that inherits from Inherits System.Windows.Forms.TextBox. In this custom...
1
1603
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 the external application window using SetParent(). The problem is, the form runs in the external application window, but the external application no...
0
7694
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...
0
7921
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. ...
1
7666
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...
0
7964
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...
0
5217
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2107
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
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.