Hello, I have a homework to do and I am sitting on it already 7 days and I cannot find out how to make graphics like :

using (Graphics g = this.CreateGraphics()
g.FillEllipse(Brushes.DarkGray, new Rectangle(45, 65, 200, 100));
g.FillEllipse(Brushes.Silver, new Rectangle(45, 60, 200, 100));

appear after you insert password abc and disappear after 3 seconds and back again appear and disappear, appear and disappear, appear and disappear.... without stopping. I already done the pice when you put the password the graphic will show up, but I cannot make it dissapear after 3 seconds and then appear after 3 seconds. Please Help!

Try using a System.Windows.Forms.Timer This is a timer for windows forms.
Toggle a ShowGraphic boolean variable in the timer tick event.
Then test the value of ShowGraphic in the form paint event.

I am not really good in programing and I really do not get what you told me XD sorry for my knowledge, but could you please explain it in very dumb easy way ^^

To make a Graphic dissapear you could first draw one.
Wait 3 secs or watever.
Draw the same grhaphic again but with the Brush in the backgroundcolor of the form.
Wait 3 secs or whatever.
Draw the graphic again with a Brush in the color you had before.

When drawing graphics an a form the best place to do this is the forms Paint event.

Select your form, then in the properties window click on the little lighining button; this opens the events list.
Scroll to the Paint event and double click to add the event handler in your code.
Now in the handler write the code to draw the graphics.
You should use the Graphics object from the PaintEventArgs object (ie. e.Graphics) to do this.

Adding a Timer is easy.
In the toolbox expand the Components group.
Just drag the timer (at the bottom of the group) on to you form.
In the properties of the timer set the interval (in your case 3000 ms).
Now double click on the timer to add the Tick event handler.

Add code in the timer tick event to turn on and off a boolean variable that you can test in the forms paint event.

The code below draws a line from the top left to bottom right of the form when checkBox1 is checked and disapears when checkBox1 is unckecked.

private void Form1_Paint(object sender, PaintEventArgs e)
            if (checkBox1.Checked)
                e.Graphics.DrawLine(Pens.Black, new Point(0, 0), (Point)this.Size);

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
            this.Invalidate(); // force form to re-paint

Edited 6 Years Ago by nick.crane: Added example program

I think that I am nearly there, but I dont know what I should put in the Timer XD. I done that, but is not working:

private void Timer1_Tick(object sender, EventArgs e)
            TMR1.Interval = 3000;
            e.Graphics.Visible = true;


That probably does not even compile.
Based on what you need to do, the TMR1.Start(); should be done only after the password has been entered correctly and not in the timer tick event.
The timer interval can be set in the properties and is not needed here. e.Graphics.Visible = true; will not compile as the 'e' is a basic EventArgs object.
You should look at my code example again. The Graphics object is in the Form_Paint event handler.
Get things working bit by bit with test code first.
Then, as you add new bits, add/change your existing code to suit what you now need.
The timer event should only need a call to this.Invalidate(); ('this' being the form).

Edited 6 Years Ago by nick.crane: n/a

Ok, it is showing up after 3 seconds, then it disapears, but only for few ms like meaby 100. I want it to stay off for 3 sec and on for 3 sec. However Thank for your help :D You helped me so much!

and one more thing why sometimes I need to minimize the winodws in oreder for graphics to show?

Edited 6 Years Ago by xGrimReaperx: n/a

I think these few mods might help with your timing.

boolean _showGraphics = false;

        private void Form1_Paint(object sender, PaintEventArgs e)
            if (_showGraphics)
                // draw graphics here

        private void Timer1_Tick(object sender, EventArgs e)
             _showGraphics = !_showGraphics;

Edited 6 Years Ago by nick.crane: n/a

The Program is finally working I just needed to write boolean with capital letter. Thank you for your help!

Edited 6 Years Ago by xGrimReaperx: n/a

This question has already been answered. Start a new discussion instead.