Need Help with System.Windows.Forms.Timer

B

Bilo

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?
If change the Constructor to
public MediaDriver(Label label1 , TrackBar trackBar1 , MainGUI maingui)
and declare MainGUI maingui ; and not Form maingui;
than it works.
The problem is that Class MediaDriver will be a separate DLL and I dont know
the which class is calling the Constructor. When someone uses a class XYZ
and calls the Constructor of the MediaDriver than it will not work.
So I must declare the constructor like
public MediaDriver(Label label1 , TrackBar trackBar1 , Form maingui)
but than I dont know how to make a timer
 
W

WineNCheese

Here's some options for you:

1. Do you have to pass in the Form to the contstructor? Couldn't you pass
an IContainer in? If some users of this class will not need an IContainer,
you could make another constructor that does not use one.

2. If you have to pass in the form, and the form will always contain a
container, you could derive your own form that contains a Container
property. Your constructor would then take as a parameter one of these Form
derived base classes.

3. If you must pass in a Form, you could determine if the incoming form
implements a specific interface you define, which allows access to a
"Components" property.

Do any of these work for you? If you need more concrete descriptions, or if
I've misunderstood your problem, let me know.

WNC
 

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