Adding Timer Control to Windows Form??????? 
Author Message
 Adding Timer Control to Windows Form???????

Hi!

The issue is that there are two kinds of timer objects in .NET, optimized
for different scenarios. You will have to specify the exact type when trying
to use either.

So, in your code below, change the:

Timer *Timer1;

to:

'System::Windows::Forms::Timer *Timer1;

Since that's the optimized version for the Windows Forms.

--
*************************************************************************
"French is the language of love, C# is for everything else..."



Quote:
> I am trying to add a timer control to a windows form through code in VC++
> .NET.

> I had no problem adding my other controls such as buttons, textboxes,
> labels, etc.....but with the timer this is not the case.

> I am getting this error (the source code is at the bottom of this message)

> error C2872: 'Timer' : ambiguous symbol

>         could be: 'System::Threading::Timer'

>         or       ''System::Windows::Forms::Timer'

> ChartForm.cpp(283) : error C2664:
> 'System::Windows::Forms::Control::ControlCollection::Add' : cannot convert
> parameter 1 from 'System::Threading::Timer __gc *' to
> 'System::Windows::Forms::Control __gc *'

> Which refers to "Controls->Add(Timer1);"

> When I tried to use the qualified name for declaring Timer:

>             System::Windows::Forms::Timer* Timer1; in the .H file and

>             Timer1 = new System::Windows::Forms::Timer(); in the .cpp file

> And got this error:

> ChartForm.cpp(283) : error C2664:
> 'System::Windows::Forms::Control::ControlCollection::Add' : cannot convert
> parameter 1 from 'System::Windows::Forms::Timer __gc *' to
> 'System::Windows::Forms::Control __gc *'

>         Types pointed to are unrelated; conversion requires
> reinterpret_cast, C-style cast or function-style cast

> Below is the source code:..

> I am not sure how to do this...can anyone please give me a hand on this?

> Delali

> ChartForm.H

> ***********************************************************************

> #using <System.dll>

> #using <System.Windows.Forms.dll>

> #using <System.Drawing.dll>

> using namespace System;

> using namespace System::ComponentModel;

> using namespace System::Windows::Forms;

> using namespace System::Drawing;

> using namespace System::Threading;

> __gc public class ChartForm : public Form{

> public:

>       ChartForm();

> private:

>       buttons . . . . works fine

>       textboxes. . . .works fine

>       labels. . . . works fine

>       Timer* Timer1

>       void Setup_Controls();

>       void Timer_Tick(Object* pSender, EventArgs* pArgs);

> };

> ***********************************************************************

> ChartForm.cpp

> ***********************************************************************

> void Setup_Controls()

> {

>  . . . buttons, labels, and textboxes . . . .

>       //Timer Setup

>       Timer1 = new Timer();

>       Timer1->Interval = 100;

>       Timer1->Tick +=new EventHandler (this, &ChartForm::Timer_Tick);

>       Controls->Add(Timer1);

> }

> void Timer_Tick(Object* pSender, EventArgs* pArgs)

> {}

> ***********************************************************************



Wed, 26 Jan 2005 16:32:27 GMT  
 Adding Timer Control to Windows Form???????
I have tried that already and got this:

Quote:
> When I tried to use the qualified name for declaring Timer:

>             System::Windows::Forms::Timer* Timer1; in the .H file and

>             Timer1 = new System::Windows::Forms::Timer(); in the .cpp file

> And got this error:

> ChartForm.cpp(283) : error C2664:
> 'System::Windows::Forms::Control::ControlCollection::Add' : cannot convert
> parameter 1 from 'System::Windows::Forms::Timer __gc *' to
> 'System::Windows::Forms::Control __gc *'

>         Types pointed to are unrelated; conversion requires
> reinterpret_cast, C-style cast or function-style cast

any suggestions on how to fix this?

Delali



- Show quoted text -

Quote:
> Hi!

> The issue is that there are two kinds of timer objects in .NET, optimized
> for different scenarios. You will have to specify the exact type when
trying
> to use either.

> So, in your code below, change the:

> Timer *Timer1;

> to:

> 'System::Windows::Forms::Timer *Timer1;

> Since that's the optimized version for the Windows Forms.

> --
> *************************************************************************
> "French is the language of love, C# is for everything else..."




> > I am trying to add a timer control to a windows form through code in
VC++
> > .NET.

> > I had no problem adding my other controls such as buttons, textboxes,
> > labels, etc.....but with the timer this is not the case.

> > I am getting this error (the source code is at the bottom of this
message)

> > error C2872: 'Timer' : ambiguous symbol

> >         could be: 'System::Threading::Timer'

> >         or       ''System::Windows::Forms::Timer'

> > ChartForm.cpp(283) : error C2664:
> > 'System::Windows::Forms::Control::ControlCollection::Add' : cannot
convert
> > parameter 1 from 'System::Threading::Timer __gc *' to
> > 'System::Windows::Forms::Control __gc *'

> > Which refers to "Controls->Add(Timer1);"

> > When I tried to use the qualified name for declaring Timer:

> >             System::Windows::Forms::Timer* Timer1; in the .H file and

> >             Timer1 = new System::Windows::Forms::Timer(); in the .cpp
file

> > And got this error:

> > ChartForm.cpp(283) : error C2664:
> > 'System::Windows::Forms::Control::ControlCollection::Add' : cannot
convert
> > parameter 1 from 'System::Windows::Forms::Timer __gc *' to
> > 'System::Windows::Forms::Control __gc *'

> >         Types pointed to are unrelated; conversion requires
> > reinterpret_cast, C-style cast or function-style cast

> > Below is the source code:..

> > I am not sure how to do this...can anyone please give me a hand on this?

> > Delali

> > ChartForm.H

> > ***********************************************************************

> > #using <System.dll>

> > #using <System.Windows.Forms.dll>

> > #using <System.Drawing.dll>

> > using namespace System;

> > using namespace System::ComponentModel;

> > using namespace System::Windows::Forms;

> > using namespace System::Drawing;

> > using namespace System::Threading;

> > __gc public class ChartForm : public Form{

> > public:

> >       ChartForm();

> > private:

> >       buttons . . . . works fine

> >       textboxes. . . .works fine

> >       labels. . . . works fine

> >       Timer* Timer1

> >       void Setup_Controls();

> >       void Timer_Tick(Object* pSender, EventArgs* pArgs);

> > };

> > ***********************************************************************

> > ChartForm.cpp

> > ***********************************************************************

> > void Setup_Controls()

> > {

> >  . . . buttons, labels, and textboxes . . . .

> >       //Timer Setup

> >       Timer1 = new Timer();

> >       Timer1->Interval = 100;

> >       Timer1->Tick +=new EventHandler (this, &ChartForm::Timer_Tick);

> >       Controls->Add(Timer1);

> > }

> > void Timer_Tick(Object* pSender, EventArgs* pArgs)

> > {}

> > ***********************************************************************



Thu, 27 Jan 2005 01:01:14 GMT  
 Adding Timer Control to Windows Form???????
You need to 'box' the Timer pointer you wish to use to hold the Timer
instance. You do this by placing the following in a .H header:

__value  struct  MyVariables
{
    static Timer *Timer1 ;

Quote:
} ;

And then initailize as follows:

MyVariables::Timer1 = new Timer( ) ;

Be sure to have following is at top of the files with these code snipets:

#using <mscorlib.dll>

#using <System.DLL>

#using <System.Windows.Forms.DLL>

#using <System.Drawing.DLL>

using namespace System::Windows::Forms ;

using namespace System::Drawing ;

using namespace System ;

This all assumes your creating managed C++ code.

  /== Peteroid ==\


Quote:
> I have tried that already and got this:

> > When I tried to use the qualified name for declaring Timer:

> >             System::Windows::Forms::Timer* Timer1; in the .H file and

> >             Timer1 = new System::Windows::Forms::Timer(); in the .cpp
file

> > And got this error:

> > ChartForm.cpp(283) : error C2664:
> > 'System::Windows::Forms::Control::ControlCollection::Add' : cannot
convert
> > parameter 1 from 'System::Windows::Forms::Timer __gc *' to
> > 'System::Windows::Forms::Control __gc *'

> >         Types pointed to are unrelated; conversion requires
> > reinterpret_cast, C-style cast or function-style cast

> any suggestions on how to fix this?

> Delali



> > Hi!

> > The issue is that there are two kinds of timer objects in .NET,
optimized
> > for different scenarios. You will have to specify the exact type when
> trying
> > to use either.

> > So, in your code below, change the:

> > Timer *Timer1;

> > to:

> > 'System::Windows::Forms::Timer *Timer1;

> > Since that's the optimized version for the Windows Forms.

> > --

*************************************************************************

- Show quoted text -

Quote:
> > "French is the language of love, C# is for everything else..."




> > > I am trying to add a timer control to a windows form through code in
> VC++
> > > .NET.

> > > I had no problem adding my other controls such as buttons, textboxes,
> > > labels, etc.....but with the timer this is not the case.

> > > I am getting this error (the source code is at the bottom of this
> message)

> > > error C2872: 'Timer' : ambiguous symbol

> > >         could be: 'System::Threading::Timer'

> > >         or       ''System::Windows::Forms::Timer'

> > > ChartForm.cpp(283) : error C2664:
> > > 'System::Windows::Forms::Control::ControlCollection::Add' : cannot
> convert
> > > parameter 1 from 'System::Threading::Timer __gc *' to
> > > 'System::Windows::Forms::Control __gc *'

> > > Which refers to "Controls->Add(Timer1);"

> > > When I tried to use the qualified name for declaring Timer:

> > >             System::Windows::Forms::Timer* Timer1; in the .H file and

> > >             Timer1 = new System::Windows::Forms::Timer(); in the .cpp
> file

> > > And got this error:

> > > ChartForm.cpp(283) : error C2664:
> > > 'System::Windows::Forms::Control::ControlCollection::Add' : cannot
> convert
> > > parameter 1 from 'System::Windows::Forms::Timer __gc *' to
> > > 'System::Windows::Forms::Control __gc *'

> > >         Types pointed to are unrelated; conversion requires
> > > reinterpret_cast, C-style cast or function-style cast

> > > Below is the source code:..

> > > I am not sure how to do this...can anyone please give me a hand on
this?

> > > Delali

> > > ChartForm.H

***********************************************************************

- Show quoted text -

Quote:

> > > #using <System.dll>

> > > #using <System.Windows.Forms.dll>

> > > #using <System.Drawing.dll>

> > > using namespace System;

> > > using namespace System::ComponentModel;

> > > using namespace System::Windows::Forms;

> > > using namespace System::Drawing;

> > > using namespace System::Threading;

> > > __gc public class ChartForm : public Form{

> > > public:

> > >       ChartForm();

> > > private:

> > >       buttons . . . . works fine

> > >       textboxes. . . .works fine

> > >       labels. . . . works fine

> > >       Timer* Timer1

> > >       void Setup_Controls();

> > >       void Timer_Tick(Object* pSender, EventArgs* pArgs);

> > > };

***********************************************************************
Quote:

> > > ChartForm.cpp

***********************************************************************

- Show quoted text -

Quote:

> > > void Setup_Controls()

> > > {

> > >  . . . buttons, labels, and textboxes . . . .

> > >       //Timer Setup

> > >       Timer1 = new Timer();

> > >       Timer1->Interval = 100;

> > >       Timer1->Tick +=new EventHandler (this, &ChartForm::Timer_Tick);

> > >       Controls->Add(Timer1);

> > > }

> > > void Timer_Tick(Object* pSender, EventArgs* pArgs)

> > > {}

***********************************************************************

- Show quoted text -



Sat, 29 Jan 2005 04:18:45 GMT  
 Adding Timer Control to Windows Form???????
Ok, I need a little help with this please.....

I am still getting the same error as before......

ChartForm.cpp(283) : error C2664:
'System::Windows::Forms::Control::ControlCollection::Add' : cannot convert
parameter 1 from 'System::Windows::Forms::Timer __gc *' to
'System::Windows::Forms::Control __gc *'

        Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast

ChartForms.h

***********************************************************************

#ifndef CHART_FORM_H

#define CHART_FORM_H

#include <tchar.h>

#using <mscorlib.dll>

#using <System.dll>

#using <System.Windows.Forms.dll>

#using <System.Drawing.dll>

#using <ChartFX.dll>

#using <ChartFX.Base.dll>

#using <ChartFX.Borders.dll>

using namespace System;

using namespace System::ComponentModel;

using namespace System::Windows::Forms;

using namespace System::Drawing;

using namespace SoftwareFX::ChartFX;

using namespace System::Threading;

#include "MyTimer.h"

// This is the entry point for this application

__gc public class ChartForm : public Form{

public:

      ChartForm();

private:

      //Buttons, textboxes, labels.....declared here and work fine

      ??????What do I need to declare here?

      MyVariables* Timer1;

      void Setup_Controls();

      void Timer_Tick(Object* pSender, EventArgs* pArgs);

Quote:
};

#endif

***********************************************************************

ChartForms.cpp

***********************************************************************

#include "stdafx.h"

#include "MyTimer.h"

#include "ChartForm.h"

#include "MyThread.h"

#using <System.dll>

#using <System.Windows.Forms.dll>

#using <System.Drawing.dll>

#using <ChartFX.dll>

#using <ChartFX.Base.dll>

#using <ChartFX.Borders.dll>

using namespace System;

using namespace System::ComponentModel;

using namespace System::Windows::Forms;

using namespace System::Drawing;

using namespace System::Threading;

ChartForm::ChartForm()

{

//Set the Form caption

    Text = "Test";

    FormBorderStyle=FormBorderStyle::Fixed3D;

    MaximizeBox = true;

    MinimizeBox = true;

    ClientSize=System::Drawing::Size(1200,800);

      Setup_Controls();

Quote:
}

void ChartForm::Setup_Controls()

{

I do not know if this is correct???????

//Timer Setup

      MyVariables::Timer1->Interval = 100;

      MyVariables::Timer1->Tick +=new EventHandler (this,
&ChartForm::Timer_Tick);

      this->Controls->Add(MyVariables::Timer1);

      MyVariables::Timer1->Enabled = true;

      MyVariables::Timer1->Start();

Quote:
}

void Timer_Tick(Object* pSender, EventArgs* pArgs)

{}

***********************************************************************

MyTimer.h

***********************************************************************

#ifndef MY_TIMER_H

#define MY_TIMER_H

#using <mscorlib.dll>

#using <System.DLL>

#using <System.Windows.Forms.DLL>

#using <System.Drawing.DLL>

using namespace System::Windows::Forms ;

using namespace System::Drawing ;

using namespace System ;

__value  struct  MyVariables

{

    static Timer *Timer1 ;

Quote:
} ;

//MyVariables::Timer1 = new Timer( ) ;

#endif;

***********************************************************************

MyTimer.cpp

***********************************************************************

#include "MyTimer.h"

is anything needed here?

***********************************************************************


Quote:
> You need to 'box' the Timer pointer you wish to use to hold the Timer
> instance. You do this by placing the following in a .H header:

> __value  struct  MyVariables
> {
>     static Timer *Timer1 ;
> } ;

> And then initailize as follows:

> MyVariables::Timer1 = new Timer( ) ;

> Be sure to have following is at top of the files with these code snipets:

> #using <mscorlib.dll>

> #using <System.DLL>

> #using <System.Windows.Forms.DLL>

> #using <System.Drawing.DLL>

> using namespace System::Windows::Forms ;

> using namespace System::Drawing ;

> using namespace System ;

> This all assumes your creating managed C++ code.

>   /== Peteroid ==\



> > I have tried that already and got this:

> > > When I tried to use the qualified name for declaring Timer:

> > >             System::Windows::Forms::Timer* Timer1; in the .H file and

> > >             Timer1 = new System::Windows::Forms::Timer(); in the .cpp
> file

> > > And got this error:

> > > ChartForm.cpp(283) : error C2664:
> > > 'System::Windows::Forms::Control::ControlCollection::Add' : cannot
> convert
> > > parameter 1 from 'System::Windows::Forms::Timer __gc *' to
> > > 'System::Windows::Forms::Control __gc *'

> > >         Types pointed to are unrelated; conversion requires
> > > reinterpret_cast, C-style cast or function-style cast

> > any suggestions on how to fix this?

> > Delali



> > > Hi!

> > > The issue is that there are two kinds of timer objects in .NET,
> optimized
> > > for different scenarios. You will have to specify the exact type when
> > trying
> > > to use either.

> > > So, in your code below, change the:

> > > Timer *Timer1;

> > > to:

> > > 'System::Windows::Forms::Timer *Timer1;

> > > Since that's the optimized version for the Windows Forms.

> > > --

> *************************************************************************
> > > "French is the language of love, C# is for everything else..."




> > > > I am trying to add a timer control to a windows form through code in
> > VC++
> > > > .NET.

> > > > I had no problem adding my other controls such as buttons,
textboxes,
> > > > labels, etc.....but with the timer this is not the case.

> > > > I am getting this error (the source code is at the bottom of this
> > message)

> > > > error C2872: 'Timer' : ambiguous symbol

> > > >         could be: 'System::Threading::Timer'

> > > >         or       ''System::Windows::Forms::Timer'

> > > > ChartForm.cpp(283) : error C2664:
> > > > 'System::Windows::Forms::Control::ControlCollection::Add' : cannot
> > convert
> > > > parameter 1 from 'System::Threading::Timer __gc *' to
> > > > 'System::Windows::Forms::Control __gc *'

> > > > Which refers to "Controls->Add(Timer1);"

> > > > When I tried to use the qualified name for declaring Timer:

> > > >             System::Windows::Forms::Timer* Timer1; in the .H file
and

> > > >             Timer1 = new System::Windows::Forms::Timer(); in the
.cpp
> > file

> > > > And got this error:

> > > > ChartForm.cpp(283) : error C2664:
> > > > 'System::Windows::Forms::Control::ControlCollection::Add' : cannot
> > convert
> > > > parameter 1 from 'System::Windows::Forms::Timer __gc *' to
> > > > 'System::Windows::Forms::Control __gc *'

> > > >         Types pointed to are unrelated; conversion requires
> > > > reinterpret_cast, C-style cast or function-style cast

> > > > Below is the source code:..

> > > > I am not sure how to do this...can anyone please give me a hand on
> this?

> > > > Delali

> > > > ChartForm.H

> ***********************************************************************

> > > > #using <System.dll>

> > > > #using <System.Windows.Forms.dll>

> > > > #using <System.Drawing.dll>

> > > > using namespace System;

> > > > using namespace System::ComponentModel;

> > > > using namespace System::Windows::Forms;

> > > > using namespace System::Drawing;

> > > > using namespace System::Threading;

> > > > __gc public class ChartForm : public Form{

> > > > public:

> > > >       ChartForm();

> > > > private:

> > > >       buttons . . . . works fine

> > > >       textboxes. . . .works fine

> > > >       labels. . . . works fine

> > > >       Timer* Timer1

> > > >       void Setup_Controls();

> > > >       void Timer_Tick(Object* pSender, EventArgs* pArgs);

> > > > };

> ***********************************************************************

> > > > ChartForm.cpp

> ***********************************************************************

> > > > void Setup_Controls()

> > > > {

> > > >  . . . buttons, labels, and textboxes . . . .

> > > >       //Timer Setup

> > > >       Timer1 = new Timer();

> > > >       Timer1->Interval = 100;

> > > >       Timer1->Tick +=new EventHandler (this,

&ChartForm::Timer_Tick);

- Show quoted text -

Quote:

> > > >       Controls->Add(Timer1);

> > > > }

> > > > void Timer_Tick(Object* pSender, EventArgs* pArgs)

...

read more »



Sat, 29 Jan 2005 23:26:29 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Displaying XML in a System.Windows.Forms.Form control

2. Adding Help to a Windows Forms App

3. Adding forms under windows 2000

4. Adding forms under windows 2000

5. How to Add Resources to Windows Forms

6. How to disable adding, inserting ord deleting Rows in the DataGrid (System.Windows.Forms.DataGrid)

7. Adding a Control to a Web Form

8. Can not add a custom .NET control on the form in design-time

9. Adding controls(mainly buttons) to SDI main form!?!

10. Unable to add custom C# control to a form - Exception from HRESULT: 0x80131019

11. Please Help - Adding Controls to a form from a child thread

12. Licensing errors when trying to add controls to a form

 

 
Powered by phpBB® Forum Software