0

I want that if i click on an image it gives a visual effect like whirl effect or glow effect or anything else on specific part around the point where i clicked with the mouse. for example if anyone has used the picture password of UC browser of windows phone exactly the same i want.

I have not tried anything because i have no knowledge of animation and graphics hence i haven't tried anything.

public void start()
 {
  messagebox.show("i haven't tried anything yet no knowledge of animation");
}

This code is nothing but i wrote it because i was not able to post the question.

  • 1
    What are you targetting: Winforms? WPF? ASP? ...?? __Always__ tag your question accordingly! – TaW Apr 02 '16 at 19:23
  • 1
    *I put nonsense in my post just to get past the filters* is a very bad start here. – Ken White Apr 02 '16 at 19:25
  • In winforms you probably want to do this: create and start a Timer on the MouseClick. Also store the e.Location where the MouseClick hit. In the Timer.Tick Invalidate the PictureBox and increment a class level counter until it hits a limit. In the PB's Paint event you can do some graphics, like DrawEllipse around the point with a radius of the counter. When the limit is hit in the Tick, stop the timer and reset the counter to a value the Paint event understands to mean: No more drawing. Done. Around 10-15 lines.. – TaW Apr 02 '16 at 19:29
  • TaW .. exactly this i want to do but can you provide me the code for this – Utkrisht Srivastav Apr 02 '16 at 19:37
  • No, I don't do WPF. Please Tag your question accordingly!!! – TaW Apr 02 '16 at 19:42
  • the solution which you gave was right give me the code for that please for windows forms – Utkrisht Srivastav Apr 02 '16 at 19:45

1 Answers1

1

In Winforms you could write code like this:

int AnimationCounter = 0;
Point AnimationCenter = Point.Empty;
Timer AnimationTimer = new Timer();

private void pictureBox1 _MouseClick(object sender, MouseEventArgs e)
{
    AnimationCenter = e.Location;
    AnimationTimer.Interval = 20;
    AnimationTimer.Start();
}

void AnimationTimer_Tick(object sender, EventArgs e)
{
    if (AnimationCounter > 15)
    {
        AnimationTimer.Stop();
        AnimationCounter = 0;
        pictureBox1.Invalidate();
    }
    else
    {
        AnimationCounter += 1;
        pictureBox1.Invalidate();
    }
}

private void pictureBox1 _Paint(object sender, PaintEventArgs e)
{
    if (AnimationCounter > 0) 
    {
        int ac = AnimationCounter / 2;
        e.Graphics.DrawEllipse(Pens.Orange, AnimationCenter.X - ac, 
                                            AnimationCenter.Y - ac, ac * 2, ac * 2);
    }
}

Don't forget to hook up the Paint and MouseClick event and also the AnimationTimer_Tick event.!

The result will draw a growing circle at the spot you click on which will disappear after ca. 10 * 20 ms..

Update: The first version suffered from repeatedly hooking up the Tick event. This one is better tested ;-)

Community
  • 1
  • 1
TaW
  • 53,122
  • 8
  • 69
  • 111
  • thanx TaW. i implemented it the result what i got was that: firstly when i clicked anywhere the ellipses which were drawn were of different sizes. Secondly when i clicked somewhere the ellipses hide when i click for the second time it should hide at the first time. – Utkrisht Srivastav Apr 02 '16 at 21:00
  • Whoops. I hadn't kept clicking enought to see it. The mistake was hooking up the event on each click, resulting in it running more and more often, leaving artifacts behind. Fixed. – TaW Apr 02 '16 at 21:18
  • yes its working but alas only for 3 times.. then the same problem and one thing more the ellipses are disappearing very quickly – Utkrisht Srivastav Apr 02 '16 at 21:31
  • It works all the time here now,; I tried 20 or more times. Maybe you have not updated all the code? You can control the speed by changing the interval; and you can and should play around with the animation.. – TaW Apr 02 '16 at 21:40
  • thanx alot TaW... it was very grateful... thumbs up for u – Utkrisht Srivastav Apr 02 '16 at 21:46
  • one more question can you tell me what is the picturebox1.invalidate(); doing? – Utkrisht Srivastav Apr 02 '16 at 21:58
  • Yes. It tells the system that the control needs to be repainted so the system triggers the `Paint` event. The system will do that whenever it needs but here we need to enforce it because we want the looks to change. We can't call the `Paint` event directly because providing the proper parameter `e` is up to the system. – TaW Apr 02 '16 at 22:02