Author Topic: C# Classes  (Read 4608 times)

0 Members and 1 Guest are viewing this topic.

Offline abc

  • Hero Member
  • *****
  • Posts: 576
    • View Profile
C# Classes
« 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.

Offline Warrior

  • supreme mac daddy of trolls
  • Hero Member
  • *****
  • Posts: 7503
  • One for a Dime two for a Quarter!
    • View Profile
Re: C# Classes
« Reply #1 on: September 15, 2007, 04:03:02 pm »
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

Offline abc

  • Hero Member
  • *****
  • Posts: 576
    • View Profile
Re: C# Classes
« Reply #2 on: September 15, 2007, 04:55:35 pm »
 ???

Offline LordVader

  • Full Member
  • ***
  • Posts: 113
  • Knowledge is power.
    • View Profile
    • James Moss on the web!
Re: C# Classes
« Reply #3 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.

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: C# Classes
« Reply #4 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.
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: C# Classes
« Reply #5 on: September 15, 2007, 11:19:18 pm »
Note that this is what Warrior said, but in a less verbose fashion.

Offline Camel

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
    • BNU Bot
Re: C# Classes
« Reply #6 on: September 16, 2007, 05:25:53 am »
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?
« Last Edit: September 16, 2007, 05:31:27 am by Camel »

<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!

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: C# Classes
« Reply #7 on: September 16, 2007, 11:40:49 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.

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.
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.