News:

Who uses forums anymore?

Main Menu

C# Classes

Started by abc, September 15, 2007, 03:21:32 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

abc

I know I've asked a similar question, but could someone post an example on how to manipulate a form through a separate class.

Warrior

Just pass your form object into the class method parameter. Simple as that
One must ask oneself: "do I will trolling to become a universal law?" And then when one realizes "yes, I do will it to be such," one feels completely justified.
-- from Groundwork for the Metaphysics of Trolling

abc


LordVader

http://csharpcomputing.com/Tutorials/calculator.htm

I'm trying to learn c# some atm, found that the other day may help.

Joe

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.
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


Sidoh

Note that this is what Warrior said, but in a less verbose fashion.

Camel

#6
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?

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!

MyndFyre

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.
Quote from: Joe on January 23, 2011, 11:47:54 PM
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Quote from: Rule on May 26, 2009, 02:02:12 PMOur species really annoys me.