Clan x86

Technical (Development, Security, etc.) => General Programming => Topic started by: abc on September 15, 2007, 03:21:32 PM

Title: C# Classes
Post by: abc on September 15, 2007, 03:21:32 PM
I know I've asked a similar question, but could someone post an example on how to manipulate a form through a separate class.
Title: Re: C# Classes
Post by: Warrior on September 15, 2007, 04:03:02 PM
Just pass your form object into the class method parameter. Simple as that
Title: Re: C# Classes
Post by: abc on September 15, 2007, 04:55:35 PM
 ???
Title: Re: C# Classes
Post by: LordVader on September 15, 2007, 05:01:42 PM
http://csharpcomputing.com/Tutorials/calculator.htm

I'm trying to learn c# some atm, found that the other day may help.
Title: Re: C# Classes
Post by: Joe on September 15, 2007, 11:12:17 PM
Try this as a constructor:

using System.Windows;
[..]
public class ClassName(Form f);


Construct it from your main form as new ClassName(this);. Hint, the this keyword always references the instance of the class that you're in, unless you're in static, in which case.. it gives some big bad error.
Title: Re: C# Classes
Post by: Sidoh on September 15, 2007, 11:19:18 PM
Note that this is what Warrior said, but in a less verbose fashion.
Title: Re: C# Classes
Post by: Camel on September 16, 2007, 05:25:53 AM
Quote from: Joex86] link=topic=10262.msg130186#msg130186 date=1189912337]
Try this as a constructor:

using System.Windows;
[..]
public class ClassName(Form f);


Construct it from your main form as new ClassName(this);. Hint, the this keyword always references the instance of the class that you're in, unless you're in static, in which case.. it gives some big bad error.

In Java, static means class-specific (as opposed to object-specific); is it the same in C#? In C/C++, it has a completely different meaning (it prevents the linker from exporting the symbols beyond the scope of the .o file - although it does not prevent you from accessing that address in memory).

In Java, the static equivalent of this is ClassName. I'd assume that is the same in C#. In Java, I do not believe you can pass a class (which you can think of as a 'static object' if you don't want to be very technical) as a parameter, since it is not an object. I haven't tried, so I could be wrong about that, but what I said makes sense in OOD, so it should be the same in C#. Can anyone confirm?
Title: Re: C# Classes
Post by: MyndFyre on September 16, 2007, 11:40:49 PM
Quote from: Camel on September 16, 2007, 05:25:53 AM
Quote from: Joex86] link=topic=10262.msg130186#msg130186 date=1189912337]
Try this as a constructor:

using System.Windows;
[..]
public class ClassName(Form f);


Construct it from your main form as new ClassName(this);. Hint, the this keyword always references the instance of the class that you're in, unless you're in static, in which case.. it gives some big bad error.

In Java, static means class-specific (as opposed to object-specific); is it the same in C#? In C/C++, it has a completely different meaning (it prevents the linker from exporting the symbols beyond the scope of the .o file - although it does not prevent you from accessing that address in memory).

In Java, the static equivalent of this is ClassName. I'd assume that is the same in C#. In Java, I do not believe you can pass a class (which you can think of as a 'static object' if you don't want to be very technical) as a parameter, since it is not an object. I haven't tried, so I could be wrong about that, but what I said makes sense in OOD, so it should be the same in C#. Can anyone confirm?

100% correct.