School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,154 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,961 people online right now. Registration is fast and FREE... Join Now!



call an external function on button click

call an external function on button click Rate Topic: -----

#1 rqmurad  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 2
  • Joined: 26-April 09


Dream Kudos: 0

Post icon  Posted 30 April 2009 - 01:21 AM

i am doing widows programming in c#
i wrote all my code in a different codefile named baseclass.cs
the form1 has its own codefile form1.cs
i cannot access any member of baseclass.cs codefile

if there is a button on form1, how i can run a function of baseclass.cs codefile with buttonclik?

how i can view a value on form 1

Attached thumbnail(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -


#2 b.ihde  Icon User is offline

  • D.I.C for life
  • Icon
  • View blog
  • Group: Contributors
  • Posts: 986
  • Joined: 29-September 08


Dream Kudos: 75

Posted 30 April 2009 - 02:42 AM

hi and welcome to DreamInCode!

Please show us what you have tried so far?
And please post also the code from your form1 :)

Thanks

Ben
Was This Post Helpful? 0
  • +
  • -

#3 InternalStatic  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 28-April 09


Dream Kudos: 0

Posted 30 April 2009 - 12:31 PM

View Postrqmurad, on 30 Apr, 2009 - 01:21 AM, said:

i am doing widows programming in c#
i wrote all my code in a different codefile named baseclass.cs
the form1 has its own codefile form1.cs
i cannot access any member of baseclass.cs codefile

if there is a button on form1, how i can run a function of baseclass.cs codefile with buttonclik?

how i can view a value on form 1


Visual Studio is actually smart enough to "pretend" that all of your code that resides in your project is actually part of the same file. So, to answer your question, imply call the functions you wish to access as if they resided in the current file! Visual Studio compiles all files in the same project as one.

Side note: Normal convention is to split up your classes into different files. Usually, every class has its own file, though you may lump them all together in one (I don't recommend this). Also, when naming your namespaces and classes, use what we call Pascal casing. All that means is that the first letter of EVERY word is capitalized. For example:

namespace PascalCasingNamespaceExample
{
public class PascalCasingClassExample
{ }
}

Hope that helped.
Was This Post Helpful? 0
  • +
  • -

#4 SixOfEleven  Icon User is online

  • XNA Developer
  • Icon
  • View blog
  • Group: Moderators
  • Posts: 4,015
  • Joined: 18-October 08


Dream Kudos: 1100

Expert In: C, C#, XNA, Game Programming, Programming Concepts

Posted 30 April 2009 - 01:16 PM

This thread might help you:

http://www.dreaminco...wtopic99852.htm
Was This Post Helpful? 0
  • +
  • -

#5 PsychoCoder  Icon User is offline

  • apt-get install DIC.bin
  • Icon
  • View blog
  • Group: Admins
  • Posts: 16,214
  • Joined: 26-July 07


Dream Kudos: 12400

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

Posted 30 April 2009 - 01:56 PM

This is a instance of nesting classes. The easiest way to accomplish would be to make the inner classes protected Take a look at this example (using your class names)

namespace MyNamespace
{
	/// <summary>
	/// Description of Class1.
	/// </summary>
	public class baseclass
	{
		protected component myComponent;
		protected rescoeff res;
		protected coefficients coef;
		protected design_calculate designCalc
			
		//constructor for the outer class
		public baseclass()
		{
			myComponent = new component();
			res = new rescoeff();
			coef = new coefficients();
			designCalc = new design_calculate();
		}
		
		protected class component
		{
			//class code here
		}
		
		protected class rescoeff
		{
			//class code here
		}
		
		protected class coefficients
		{
			//class code here
		}
		
		protected class design_calculate
		{
			//class code here
		}
	}
}



Then in every class you want to access these inherit from baseclass

public class MyClass : baseclass
{
		 //in our constructor we will access another class
		public MyClass()
		{
			   //now you can access the nested class like so
			   // notice that myComponent is a protected member of component
			  myComponent.SomeFunction = "BlahBlah";
		 }
}



Hope that makes sense :)
Was This Post Helpful? 0
  • +
  • -

#6 rossporter  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 9
  • Joined: 30-April 09


Dream Kudos: 0

Posted 30 April 2009 - 09:19 PM

View Postrqmurad, on 30 Apr, 2009 - 01:21 AM, said:

i am doing widows programming in c#
i wrote all my code in a different codefile named baseclass.cs
the form1 has its own codefile form1.cs
i cannot access any member of baseclass.cs codefile

if there is a button on form1, how i can run a function of baseclass.cs codefile with buttonclik?

how i can view a value on form 1


Simple issue of class visibility. The default access modifier of a C# class is private. Your class "baseclass" is therefore private as it is not declared for public, protected, or internal access.

Since baseclass does not contain any state and appears to be only a container for other public classes, I would suggest you use a namespace to contain the other classes rather than a class. If you have another reason to make this a class, then I would suggest changing the declaration to either
	 public class baseclass
	 //OR
	 internal class baseclass



public classes are visibile to all code, outside and inside of the assembly (i.e. project).

internal classes are visible to any code within the assembly.

protected classes are visible only to other classes which inherit from their container class and cannot be directly declared in a namespace.

protected internal classes are visible to the current assembly and to any classes which inherit from their container class. They also cannot be directly delcared in a namespace.

Hope it helps
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month