Click here to Skip to main content
15,909,897 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to Create one Circle. It would be appear in the exact middle of form.
after few secs it would be disappear. It would appear right side (from the centre) with the exact 5 inches gap. same like left side 5 inches gap
Posted

1 solution

Handle the Form Paint event, and add a Timer to your form.
Set the Timer to an interval of a few seconds (the Interval Property is in milliseconnds, so 1000 is a second) and handle the timer Tick event.
Add a variable to your form class, int will do for the moment, but an enum would be better.
In the Tick event handler, increase the value of your variable by one, and call the Invalidate method.
In the Paint event, check the value of the variable, modulo 4 - this will gace a value between 0 and 3 inclusive.
If it is 0, do not draw anything
If it is 1, Draw your circle in the middle.
If it is 2, Draw your circle to the left.
If it is 3, Draw your circle to the right.

You can draw the circle using the e.Graphics context provided in the handler, and by calling its DrawEllipse method[^]
Pen blackPen = new Pen(Color.Black, 3);
    int width = 200;
    int height = 200;
    int x = (Width - width) / 2;
    int y = 0;

    e.Graphics.DrawEllipse(blackPen, x, y, width, height);
That will draw your circle, horizontally centred.

You will have to play with the positions of your left and right circles, as screen sizes vary, so moving "5 inches to the left" is harder to work out.


"Above code is not working ?
I have 3 Images (Image1, Image2, Image3),

Using a timer control with interval value of 5000, i.e 5second, I
want to accomplish the following:

- Initially, only Image1 is visible to the user middle of the form, i.e the 2 images
are set to be invisible.
- When load the form appear and image1
appears exact middle of the form
- After 5 seconds, the image1 disappear and image 2 appears right side.
- After 5 seconds, the image2 disappear and image3 appears left side
- After 5 seconds, the image3 disappear and the image1 appear

I am setting timer control's Enable property to "True" in Design
time.
I am setting timer control's Interval property value to 5000 in
Design Time.

I assume that I do all the coding but not working only displaying two images


Can anyone help me code what I want to accomplish?"


First, check that you are handling the Timer Tick event - highlight the timer then look in the properties pane, click the Events button (it looks like a lightning bolt) and check the Tick event. If you have no handler, creat one by double clicking on it.

In the event handler method you will need:
A class level "mode" variable:
C#
private enum ShowImage
    {
    FirstOnly,
    SecondOnly,
    ThirdOnly,
    }
private ShowImage showWhichImage = ShowImage.FirstOnly;

In the handler method, you use this to determine what to show next:
C#
switch(showWhichImage)
    {
    case ShowImage.FirstOnly:
        Image1.Visible = false;
        Image2.Visible = true;
        Image3.Visible = false;
        showWhichImage = ShowImage.SecondOnly;
        break;
    case ShowImage.SecondOnly:
        Image1.Visible = false;
        Image2.Visible = false;
        Image3.Visible = true;
        showWhichImage = ShowImage.ThirdOnly;
        break;
    case ShowImage.ThirdOnly:
        Image1.Visible = true;
        Image2.Visible = false;
        Image3.Visible = false;
        showWhichImage = ShowImage.FirstOnly;
        break;
    default:
        throw new Exception("Unknown ShowImage encountered: " + showWhichImage.ToString());
    }
 
Share this answer
 
v2
Comments
siri2012 12-Mar-12 8:33am    
Above code is not working ?
I have 3 Images (Image1, Image2, Image3),

Using a timer control with interval value of 5000, i.e 5second, I
want to accomplish the following:

- Initially, only Image1 is visible to the user middle of the form, i.e the 2 images
are set to be invisible.
- When load the form appear and image1
appears exact middle of the form
- After 5 seconds, the image1 disappear and image 2 appears right side.
- After 5 seconds, the image2 disappear and image3 appears left side
- After 5 seconds, the image3 disappear and the image1 appear

I am setting timer control's Enable property to "True" in Design
time.
I am setting timer control's Interval property value to 5000 in
Design Time.

I assume that I do all the coding but not working only displaying two images


Can anyone help me code what I want to accomplish?
OriginalGriff 12-Mar-12 8:57am    
Answer updated
siri2012 13-Mar-12 1:57am    
Thanks a lot Friend above is working
siri2012 13-Mar-12 1:59am    
Thanks a lot frined the above code is working
OriginalGriff 13-Mar-12 4:11am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900