- using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Text;
-
using System.Windows.Forms;
-
-
namespace timertest
-
{
-
public partial class Form1 : Form
-
{
-
-
public Form1()
-
{
-
InitializeComponent();
-
}
-
-
int a = 0;
-
-
System.Windows.Forms.Timer timer = new Timer();
-
-
System.Windows.Forms.Timer timer2 = new Timer();
-
-
public void flash(object sender, EventArgs e)
-
{
-
if (this.BackColor == System.Drawing.Color.Red)
-
{
-
this.BackColor = System.Drawing.Color.White;
-
}
-
else
-
{
-
this.BackColor = System.Drawing.Color.Red;
-
}
-
Invalidate();
-
}
-
-
public void noflash(object sender, EventArgs e)
-
{
-
{
-
timer.Stop;
-
timer2.top;
-
}
-
}
-
-
private void button1_Click(object sender, EventArgs e)
-
{
-
timer.Interval = 300;
-
timer2.Interval = 3000;
-
timer.Start();
-
timer2.Start();
-
timer.Tick += new EventHandler(flash);
-
timer2.Tick += new EventHandler(noflash);
-
}
-
}
-
}
//This is code I wrote to test a routine to cause a windows form to flash when a specific event occurs. In this code the event is button1_click. The problem I have is when I click the button the form flashes until timer2 stops at which point I presume the "noflash" method has been called by the timer2.Tick event. But when I click the button again the form does nothing. When I click the button the third time, the form flashes again, acting as if the flash action has been toggled.
Why is this happening, are the timers not actually being stopped, is timer2 really stopping or not. I am very confused, please help a guuy out.
3 1330
You should not be assigning MORE event handlers everytime a button is clicked. They should be assigned once. Or assigned, then removed, and assigned again, although there's no reason for that.
I'm not sure how that answers my question. Is assigning an event the reason the form is only flashing every other time I click? How do I get the form to flash every time I click the button?
You should not be assigning MORE event handlers everytime a button is clicked. They should be assigned once. Or assigned, then removed, and assigned again, although there's no reason for that.
Whoa, I know what you meant, it was the problem. I moved it into the Form class declaration Thank you very much. I was pulling my hair out over this one.
I'm not sure how that answers my question. Is assigning an event the reason the form is only flashing every other time I click? How do I get the form to flash every time I click the button?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Alexander Jhin |
last post by:
I have this very basic Custom Control:
public class TestPanel : Panel
{
public TestPanel() : base()
{
this.SetStyle(
ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque |...
|
by: Marge Inoferror |
last post by:
I am trying to display a number of images and have them scale when the
window is resized.
I have all the code to draw the window in an OnPaint() override.
However, it only draws correctly the...
|
by: Chan |
last post by:
Invalidate() is a member of System.Windows.Forms.Form. It marks an area of
the client window as invalid and, therefore, in need of repainting, and then
makes sure a Paint event is raised.
But...
|
by: jerry chapman |
last post by:
Based on a mouse click I change something on the screen. I then want to
repaint the screen to show the change. When I tried to use .Invalidate in my
mouse routine, I got a compilation error.
...
|
by: RS |
last post by:
if i want to invalidate the client area of my Windows.Form
and execute an overrided OnPaint i would use
Form1.ActiveForm.Invalidate() ?? However, when i use this
line of code i receive a :
An...
|
by: SamSpade |
last post by:
picDocument is a picturebox
When I do picDocument.Invalidate() the box paints.
But if instead I do picDocument.Refresh() the box does not paint.
What does Refresh do. I guessed it did an...
|
by: grayaii |
last post by:
Hi,
I have a simple form that handles all its paint functionality like so:
this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque, true);
And the entry point to this...
|
by: sean |
last post by:
I'm trying to create "rubber-band" rectangles by overriding the
OnPaint method to place rectangles on top of all graphic controls, but
when I call Me.Invalidate() (when the user moves the mouse),...
|
by: raylopez99 |
last post by:
Hi,
I'm getting into GDI+ Forms 2.0 graphics for C#3 using Visual Studio
2008.
One thing I notice: the graphics are really slow and flicker on a
Pentium IV, with 2 GB RAM, even with...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
| |