Need help with System.Windows.Forms.Timer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bilo

    Need help with System.Windows.Forms.Timer

    I have a Windows Forms Class MainGUI
    I have declared
    MainGUI maingui;
    public System.Componen tModel.Containe r 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(Lab el label1 , TrackBar trackBar1 , Form maingui)
    {
    ....
    this.timer1 = new
    System.Windows. Forms.Timer(thi s.maingui.compo nents);
    this.timer1.Ena bled = true;
    this.timer1.Tic k += new System.EventHan dler(this.timer 1_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?




  • Will Pittenger

    #2
    Re: Need help with System.Windows. Forms.Timer

    I believe that class needs a window. It is based on the standard Win32
    timers. Try using System.Timers.T imer 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:will.pit tenger@verizon. net
    All mail filtered by Qurb (www.qurb.com)
    "Bilo" <justler123@yah oo.com> wrote in message
    news:OiY7%23pnI EHA.3508@TK2MSF TNGP09.phx.gbl. ..[color=blue]
    > I have a Windows Forms Class MainGUI
    > I have declared
    > MainGUI maingui;
    > public System.Componen tModel.Containe r 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(Lab el label1 , TrackBar trackBar1 , Form maingui)
    > {
    > ....
    > this.timer1 = new
    > System.Windows. Forms.Timer(thi s.maingui.compo nents);
    > this.timer1.Ena bled = true;
    > this.timer1.Tic k += new System.EventHan dler(this.timer 1_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?[/color]


    Comment

    • Bilo

      #3
      Re: Need help with System.Windows. Forms.Timer

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

      {
      private System.Componen tModel.Containe r 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_Cli ck(object sender, System.EventArg s e)
      {
      if (mediadriver == null)
      mediadriver = new MediaDriver(lab el1, trackBar1, maingui);
      maingui.mediadr iver.open_media ();
      }

      }

      class MediaDriver
      {
      ....
      Form maingui;
      private System.Windows. Forms.TrackBar trackBar1;
      private System.Windows. Forms.Timer timer1;
      ....
      public MediaDriver(Lab el label1 , TrackBar trackBar1 , Form maingui)
      {
      ....
      this.timer1 = new
      System.Windows. Forms.Timer(thi s.maingui.compo nents);
      this.timer1.Ena bled = true;
      this.timer1.Tic k += new System.EventHan dler(this.timer 1_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(Lab el 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" <will.pittenger @verizon.net> schrieb im Newsbeitrag
      news:e2worznIEH A.1048@TK2MSFTN GP12.phx.gbl...[color=blue]
      > I believe that class needs a window. It is based on the standard Win32
      > timers. Try using System.Timers.T imer instead. I may be more familiar[/color]
      with[color=blue]
      > C++ than C#, but I do not see a window in the code you listed.
      >
      > ----------
      > Will Pittenger
      > E-Mail: mailto:will.pit tenger@verizon. net
      > All mail filtered by Qurb (www.qurb.com)
      > "Bilo" <justler123@yah oo.com> wrote in message
      > news:OiY7%23pnI EHA.3508@TK2MSF TNGP09.phx.gbl. ..[color=green]
      > > I have a Windows Forms Class MainGUI
      > > I have declared
      > > MainGUI maingui;
      > > public System.Componen tModel.Containe r 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(Lab el label1 , TrackBar trackBar1 , Form maingui)
      > > {
      > > ....
      > > this.timer1 = new
      > > System.Windows. Forms.Timer(thi s.maingui.compo nents);
      > > this.timer1.Ena bled = true;
      > > this.timer1.Tic k += new[/color][/color]
      System.EventHan dler(this.timer 1_Tick);[color=blue][color=green]
      > > ....
      > > }
      > > But i get an error
      > > 'System.Windows .Forms.Form' does not contain a definition for[/color][/color]
      'components'[color=blue][color=green]
      > >
      > > How can I solve this? How can I add a Timer for the MainGUI form in the
      > > Class MediaDriver?[/color]
      >
      >[/color]


      Comment

      • Will Pittenger

        #4
        Re: Need help with System.Windows. Forms.Timer

        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:will.pit tenger@verizon. net
        All mail filtered by Qurb (www.qurb.com)
        "Bilo" <justler123@yah oo.com> wrote in message
        news:eSXS78nIEH A.2656@TK2MSFTN GP11.phx.gbl...[color=blue]
        > The class MainGUI in a windows Form. Have only paste the needed parts.
        > public class MainGUI : System.Windows. Forms.Form
        >
        > {
        > private System.Componen tModel.Containe r 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_Cli ck(object sender, System.EventArg s e)
        > {
        > if (mediadriver == null)
        > mediadriver = new MediaDriver(lab el1, trackBar1, maingui);
        > maingui.mediadr iver.open_media ();
        > }
        >
        > }
        >
        > class MediaDriver
        > {
        > ....
        > Form maingui;
        > private System.Windows. Forms.TrackBar trackBar1;
        > private System.Windows. Forms.Timer timer1;
        > ....
        > public MediaDriver(Lab el label1 , TrackBar trackBar1 , Form maingui)
        > {
        > ....
        > this.timer1 = new
        > System.Windows. Forms.Timer(thi s.maingui.compo nents);
        > this.timer1.Ena bled = true;
        > this.timer1.Tic k += new System.EventHan dler(this.timer 1_Tick);
        > ....
        > }
        >
        > ....
        > //Here comes the other Methods
        > ....
        > }
        >
        > It would work when I declare "MainGUI maingui" instead of "Form maingui"[/color]
        in[color=blue]
        > Class MediaDriver and change
        > Constructor to public MediaDriver(Lab el 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" <will.pittenger @verizon.net> schrieb im Newsbeitrag
        > news:e2worznIEH A.1048@TK2MSFTN GP12.phx.gbl...[color=green]
        > > I believe that class needs a window. It is based on the standard Win32
        > > timers. Try using System.Timers.T imer instead. I may be more familiar[/color]
        > with[color=green]
        > > C++ than C#, but I do not see a window in the code you listed.
        > >
        > > ----------
        > > Will Pittenger
        > > E-Mail: mailto:will.pit tenger@verizon. net
        > > All mail filtered by Qurb (www.qurb.com)
        > > "Bilo" <justler123@yah oo.com> wrote in message
        > > news:OiY7%23pnI EHA.3508@TK2MSF TNGP09.phx.gbl. ..[color=darkred]
        > > > I have a Windows Forms Class MainGUI
        > > > I have declared
        > > > MainGUI maingui;
        > > > public System.Componen tModel.Containe r 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(Lab el label1 , TrackBar trackBar1 , Form[/color][/color][/color]
        maingui)[color=blue][color=green][color=darkred]
        > > > {
        > > > ....
        > > > this.timer1 = new
        > > > System.Windows. Forms.Timer(thi s.maingui.compo nents);
        > > > this.timer1.Ena bled = true;
        > > > this.timer1.Tic k += new[/color][/color]
        > System.EventHan dler(this.timer 1_Tick);[color=green][color=darkred]
        > > > ....
        > > > }
        > > > But i get an error
        > > > 'System.Windows .Forms.Form' does not contain a definition for[/color][/color]
        > 'components'[color=green][color=darkred]
        > > >
        > > > How can I solve this? How can I add a Timer for the MainGUI form in[/color][/color][/color]
        the[color=blue][color=green][color=darkred]
        > > > Class MediaDriver?[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • mikeb

          #5
          Re: Need help with System.Windows. Forms.Timer

          Bilo wrote:[color=blue]
          > The class MainGUI in a windows Form. Have only paste the needed parts.
          > public class MainGUI : System.Windows. Forms.Form
          >
          > {
          > private System.Componen tModel.Containe r 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_Cli ck(object sender, System.EventArg s e)
          > {
          > if (mediadriver == null)
          > mediadriver = new MediaDriver(lab el1, trackBar1, maingui);
          > maingui.mediadr iver.open_media ();
          > }
          >
          > }
          >
          > class MediaDriver
          > {
          > ....
          > Form maingui;
          > private System.Windows. Forms.TrackBar trackBar1;
          > private System.Windows. Forms.Timer timer1;
          > ....
          > public MediaDriver(Lab el label1 , TrackBar trackBar1 , Form maingui)
          > {
          > ....
          > this.timer1 = new
          > System.Windows. Forms.Timer(thi s.maingui.compo nents);
          > this.timer1.Ena bled = true;
          > this.timer1.Tic k += new System.EventHan dler(this.timer 1_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(Lab el 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[/color]

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

          System.Windows. Forms.Timer(thi s.maingui.compo nents);

          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.Ena bled = true;
          this.timer1.Tic k += new System.EventHan dler(this.timer 1_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.compone nts field is private.

          --
          mikeb

          Comment

          Working...