I'm having some difficulty implimenting a timer in my Windows.Forms project. I want the application to present a single Form for a specific period of time and close itself (currently I have the timer popping a message box with a 'hello' message).
My project is compiling properly, but the timer isn't working. I've read many posts, read the Microsoft guides and other resources and can't seem to figure this one out.
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System:ata;
using namespace System:rawing;
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
createTimer();
InitializeTimer();
}
First, your program is C++/CLI and you shoud therefore ask your question in the appropriate Managed C++ and C++/CLI forum.
On first sight I can tell you the following about your program: You have two timer objects here, one that you probably added using the IDE (timer1) and one you create locally in your function createTimer() that is named mytimer1. These two timer objects are completely unrelated, and in particular your timer object named mytimer1 is unrelated to the function with the same name that is a member of the form class. This function is obviously intended to pop up your message box, and it would most likely do so if it ever would be called.
Moreover, the timer object named mytimer1 that you create in createTimer() is completely useless as it is bound to a local variable that goes out of scope once createTimer() finishes, i.e. instantly.
You also have an event handler for the timer1 tick event (timer1_Tick_1()) that should call MessageBox::Show(), but it is empty and thus does nothing.
Probably more details over there in the other forum.
Please use code tags when you post code next time. It will make your post much more readable.
Ah, and... Welcome to CodeGuru!
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Thank you Eri - your guidance helped me get it going. I really appreciate you taking the time.
Congratulations, you're welcome.
(I looked for code tags when I pasted my code, but didn't see any available).
The Standard as well as the Advanced Post Editor has a button that looks like the one in the attached image. It will either insert code tags and place the cursor between them for you to enter code, or it will wrap the code tags around the selected text.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
edit : holy sh!t... after many years being a member I found this option in my settings. Why isn't this enabled by default ?
I actually don't remember any more what the original default setting in my User CP was after joining, as I changed it to the Advanced Editor before making my first post. Later I found out that the Advanced Editor has certain bugs that make it practically unusable for me (and some others), so I switched to the Standard Editor and was surprised how little I missed there. (See http://www.codeguru.com/forum/showthread.php?t=501226.)
Just curious: What was it set to in your profile before you read this thread here?
I'm always happy if I happen to know something that even helps one of the forum celebrities...
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.