473,386 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Need help with System.Windows.Forms.Timer

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
4 3108
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bilo | last post by:
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...
10
by: WhiteSocksGuy | last post by:
Help! I am new to Visual Basic .Net (version 2002) and I am trying to get a System.Timers.Timer to work for me to display a splash screen for about two seconds and then load the main form. I have...
8
by: Stephen Rice | last post by:
Hi, I have a periodic problem which I am having a real time trying to sort. Background: An MDI VB app with a DB on SQL 2000. I have wrapped all the DB access into an object which spawns a...
0
by: Paul | last post by:
I have no idea why this error keeps cropping up randomly on some client machines. Is there a bug in the timer class? Paul System.InvalidOperationException: Handle is not initialized. at...
4
by: Nijazi Halimaji | last post by:
Hi everybody I have created a new timer object WithEvents tmr_check As New System.Timers.Timer On my form_Load-Event I activated the timer... Then I made a label on my form and putted on...
1
by: melanieab | last post by:
Hi, I'm have a datagrid, and I'm trying to have a tooltip pop up if a cell has been hovered on for 2 seconds. I was thinking of using DataGrid.Hover, but then decided to try this instead: ...
4
by: Lemune | last post by:
Hello everyone. I'm using vb 2005. I'm creating program that run as service on windows. And in my program I need to use timer, so I'm using timer object from component. I try my source code on...
7
by: Brian | last post by:
hello Gentlemen, been trying to get a shell program working where I have a Windows service that also has a Notification icon in the system tray..... I got this idea from microsofts Visual...
7
by: traafat | last post by:
Hello guys, i am having a problem using Delegates, i am pretty new to C# , i am starting to fall in love with it its really good language (coming from Java and Delphi), now i am working on an...
15
by: active | last post by:
Below is a small but complete program that appears to show you can't retrive a Palette from the clipboard. This is true whether the palette is placed on the clipboard by Photoshop or Photoshop...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.