Trying to create a dynamic class...?

G

Gorfy

Hey everyone. This is only my first week with C#, but I use actionscript a
lot in Flash, so I have a very basic understanding of programming, but bear
with me...

I am trying to create a "FadeClass" that I can use to fade windows in my
programs. I am using Visual C# 2008 Express right now.

This is my "Form1.cs" in it's current state:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace WindowsFormsApplication1
{
public partial class IntroBox : Form
{
public IntroBox()
{
InitializeComponent();
faderClass(this, "out", 2000);
System.Timers.Timer fadeTimer = new System.Timers.Timer();
fadeTimer.Elapsed += new ElapsedEventHandler(OnTimer);
fadeTimer.Interval = 50;
fadeTimer.Enabled = true;
fadeTimer.SynchronizingObject = this;
fadeTimer.Start();
}

private void OnTimer(Object source, ElapsedEventArgs e)
{
this.Opacity += 0.1;
}
}
}

That works. The program loads up and the first window fades in perfectly.
Here is my "faderClass.cs" which is what I'm trying to get working. I'm
trying to understand how to make the class know which window it needs to fade
(in Flash it was very easy). You can see what I've tried in the code, but to
no avail:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Timers;

namespace WindowsFormsApplication1
{
class faderClass
{
public void Main(****** target, String inOut, int fadeTime)
{
System.Timers.Timer fadeTimer = new System.Timers.Timer();
fadeTimer.Elapsed += new ElapsedEventHandler(OnTimer);
fadeTimer.Interval = 50;
fadeTimer.Enabled = true;
fadeTimer.SynchronizingObject = target;
fadeTimer.Start();
}
private void OnTimer(object source, ElapsedEventArgs e)
{
target.Opacity += 0.1;
}
}
}

As you can see, I'm lost in 2 places... First of all I don't know what to
put where the stars ****** are, and second, I want to be able to use the
"target" variable in the OnTimer ElapsedEventHandler. Basically I would want
to call the function like so:

faderClass(this, "in", 2000);

So my class knows what to fade (this), which way to fade it (in or out), and
how long it should take (2 seconds). Any and all help is MUCH appreciated.
Thanks!
 
G

Gorfy

Looks like the code is error free now! I appreciate the help. However it
seems I am still not familiar enough with this because I have a different
problem now:

The code of my "Form1.cs" starts like this:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class IntroBox : Form
{
public IntroBox()
{
InitializeComponent();
faderClass(this, "out", 2000);
....

And the code error I get for that last line is "Windows
FormsApplication1.faderClass is a type but is used like a variable." In
actionscript that is how we called a function (or class) but it seems that I
am missing something in C#
 
G

Gorfy

Okay I changed that line of code to this:

faderClass fader1 = new faderClass(this, "in", 2000);

but now it's telling me that WindowsFormsApplication1.faderClass does not
contain a constructor that takes 3 arguments...
 
G

Gorfy

Okay problems solved... learned a lot...

It would be a good idea for me to add "using System.Windows.Forms;" to the
faderClass.cs since I use the "Form" type.

=D

Cheers and thanks for your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top