By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,932 Members | 1,547 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,932 IT Pros & Developers. It's quick & easy.

Need help with System.Windows.Forms.Timer

P: n/a
I have a Windows Forms Class MainGUI
I have declared
MainGUI maingui;
public System.ComponentModel.Container components = new Container();
in the Class

I call another class MediaDriver with the Constructor

class MediaDriver
{
....
Form maingui;
private System.Windows.Forms.TrackBar trackBar1;
private System.Windows.Forms.Timer timer1;
....
public MediaDriver(Label label1 , TrackBar trackBar1 , Form maingui)
{
....
this.timer1 = new
System.Windows.Forms.Timer(this.maingui.components );
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
....
}
But i get an error
'System.Windows.Forms.Form' does not contain a definition for 'components'

How can I solve this? How can I add a Timer for the MainGUI form in the
Class MediaDriver?


Nov 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
I believe that class needs a window. It is based on the standard Win32
timers. Try using System.Timers.Timer instead. I may be more familiar with
C++ than C#, but I do not see a window in the code you listed.

----------
Will Pittenger
E-Mail: mailto:wi************@verizon.net
All mail filtered by Qurb (www.qurb.com)
"Bilo" <ju********@yahoo.com> wrote in message
news:Oi****************@TK2MSFTNGP09.phx.gbl...
I have a Windows Forms Class MainGUI
I have declared
MainGUI maingui;
public System.ComponentModel.Container components = new Container();
in the Class

I call another class MediaDriver with the Constructor

class MediaDriver
{
....
Form maingui;
private System.Windows.Forms.TrackBar trackBar1;
private System.Windows.Forms.Timer timer1;
....
public MediaDriver(Label label1 , TrackBar trackBar1 , Form maingui)
{
....
this.timer1 = new
System.Windows.Forms.Timer(this.maingui.components );
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
....
}
But i get an error
'System.Windows.Forms.Form' does not contain a definition for 'components'

How can I solve this? How can I add a Timer for the MainGUI form in the
Class MediaDriver?

Nov 16 '05 #2

P: n/a
The class MainGUI in a windows Form. Have only paste the needed parts.
public class MainGUI : System.Windows.Forms.Form

{
private System.ComponentModel.Container components = null;
Maingui maingui;
MediaDriver mediadriver;
.....
// HERE ARE ALL LABELS; BUTTONS and so on which are in the form
///

than I have somewhere a button event

private void file_button_Click(object sender, System.EventArgs e)
{
if (mediadriver == null)
mediadriver = new MediaDriver(label1, trackBar1, maingui);
maingui.mediadriver.open_media();
}

}

class MediaDriver
{
....
Form maingui;
private System.Windows.Forms.TrackBar trackBar1;
private System.Windows.Forms.Timer timer1;
....
public MediaDriver(Label label1 , TrackBar trackBar1 , Form maingui)
{
....
this.timer1 = new
System.Windows.Forms.Timer(this.maingui.components );
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
....
}

....
//Here comes the other Methods
.....
}

It would work when I declare "MainGUI maingui" instead of "Form maingui" in
Class MediaDriver and change
Constructor to public MediaDriver(Label label1 , TrackBar trackBar1 ,
MainGUI maingui)

But the problem is that Class MediaDriver will be a DLL and someone could
use this DLL from a class
XYZ and than there would be no definition for MainGUI
"Will Pittenger" <wi************@verizon.net> schrieb im Newsbeitrag
news:e2**************@TK2MSFTNGP12.phx.gbl...
I believe that class needs a window. It is based on the standard Win32
timers. Try using System.Timers.Timer instead. I may be more familiar with C++ than C#, but I do not see a window in the code you listed.

----------
Will Pittenger
E-Mail: mailto:wi************@verizon.net
All mail filtered by Qurb (www.qurb.com)
"Bilo" <ju********@yahoo.com> wrote in message
news:Oi****************@TK2MSFTNGP09.phx.gbl...
I have a Windows Forms Class MainGUI
I have declared
MainGUI maingui;
public System.ComponentModel.Container components = new Container();
in the Class

I call another class MediaDriver with the Constructor

class MediaDriver
{
....
Form maingui;
private System.Windows.Forms.TrackBar trackBar1;
private System.Windows.Forms.Timer timer1;
....
public MediaDriver(Label label1 , TrackBar trackBar1 , Form maingui)
{
....
this.timer1 = new
System.Windows.Forms.Timer(this.maingui.components );
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick); ....
}
But i get an error
'System.Windows.Forms.Form' does not contain a definition for 'components'
How can I solve this? How can I add a Timer for the MainGUI form in the
Class MediaDriver?


Nov 16 '05 #3

P: n/a
Then you may need someone better with C# and .NET than I am. All I can
suggest now is putting the timer in the form. Did you attempt to use the
other class? It works whether or not you have a form, container, or
anything else.

----------
Will Pittenger
E-Mail: mailto:wi************@verizon.net
All mail filtered by Qurb (www.qurb.com)
"Bilo" <ju********@yahoo.com> wrote in message
news:eS**************@TK2MSFTNGP11.phx.gbl...
The class MainGUI in a windows Form. Have only paste the needed parts.
public class MainGUI : System.Windows.Forms.Form

{
private System.ComponentModel.Container components = null;
Maingui maingui;
MediaDriver mediadriver;
.....
// HERE ARE ALL LABELS; BUTTONS and so on which are in the form
///

than I have somewhere a button event

private void file_button_Click(object sender, System.EventArgs e)
{
if (mediadriver == null)
mediadriver = new MediaDriver(label1, trackBar1, maingui);
maingui.mediadriver.open_media();
}

}

class MediaDriver
{
....
Form maingui;
private System.Windows.Forms.TrackBar trackBar1;
private System.Windows.Forms.Timer timer1;
....
public MediaDriver(Label label1 , TrackBar trackBar1 , Form maingui)
{
....
this.timer1 = new
System.Windows.Forms.Timer(this.maingui.components );
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
....
}

....
//Here comes the other Methods
....
}

It would work when I declare "MainGUI maingui" instead of "Form maingui" in Class MediaDriver and change
Constructor to public MediaDriver(Label label1 , TrackBar trackBar1 ,
MainGUI maingui)

But the problem is that Class MediaDriver will be a DLL and someone could
use this DLL from a class
XYZ and than there would be no definition for MainGUI
"Will Pittenger" <wi************@verizon.net> schrieb im Newsbeitrag
news:e2**************@TK2MSFTNGP12.phx.gbl...
I believe that class needs a window. It is based on the standard Win32
timers. Try using System.Timers.Timer instead. I may be more familiar

with
C++ than C#, but I do not see a window in the code you listed.

----------
Will Pittenger
E-Mail: mailto:wi************@verizon.net
All mail filtered by Qurb (www.qurb.com)
"Bilo" <ju********@yahoo.com> wrote in message
news:Oi****************@TK2MSFTNGP09.phx.gbl...
I have a Windows Forms Class MainGUI
I have declared
MainGUI maingui;
public System.ComponentModel.Container components = new Container();
in the Class

I call another class MediaDriver with the Constructor

class MediaDriver
{
....
Form maingui;
private System.Windows.Forms.TrackBar trackBar1;
private System.Windows.Forms.Timer timer1;
....
public MediaDriver(Label label1 , TrackBar trackBar1 , Form maingui) {
....
this.timer1 = new
System.Windows.Forms.Timer(this.maingui.components );
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick); ....
}
But i get an error
'System.Windows.Forms.Form' does not contain a definition for 'components'
How can I solve this? How can I add a Timer for the MainGUI form in the Class MediaDriver?



Nov 16 '05 #4

P: n/a
Bilo wrote:
The class MainGUI in a windows Form. Have only paste the needed parts.
public class MainGUI : System.Windows.Forms.Form

{
private System.ComponentModel.Container components = null;
Maingui maingui;
MediaDriver mediadriver;
.....
// HERE ARE ALL LABELS; BUTTONS and so on which are in the form
///

than I have somewhere a button event

private void file_button_Click(object sender, System.EventArgs e)
{
if (mediadriver == null)
mediadriver = new MediaDriver(label1, trackBar1, maingui);
maingui.mediadriver.open_media();
}

}

class MediaDriver
{
....
Form maingui;
private System.Windows.Forms.TrackBar trackBar1;
private System.Windows.Forms.Timer timer1;
....
public MediaDriver(Label label1 , TrackBar trackBar1 , Form maingui)
{
....
this.timer1 = new
System.Windows.Forms.Timer(this.maingui.components );
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
....
}

....
//Here comes the other Methods
....
}

It would work when I declare "MainGUI maingui" instead of "Form maingui" in
Class MediaDriver and change
Constructor to public MediaDriver(Label label1 , TrackBar trackBar1 ,
MainGUI maingui)

But the problem is that Class MediaDriver will be a DLL and someone could
use this DLL from a class
XYZ and than there would be no definition for MainGUI


Since the components field is part of the MainGUI GUI class (and not
Form), what do you want:

System.Windows.Forms.Timer(this.maingui.components );

to do if a non-MainGUI Form is passed into the MediaDriver constructor?

If you want the timer to be skipped if MediaDriver's maingui is not a
MainGUI object, then you could code something like:

MainGUI x = maingui as MainGUI;
if (x != null) {
this.timer1 = new
System.Windows.Forms.Timer( x.components);
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
}

but, I suspect that you need to think through what should really happen
in this case.

Also, unless there's a typo in your example, I don't see how this would
compile anyway, since the MainGUI.components field is private.

--
mikeb
Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.