出现消失的圈子 [英] Appear & Dissappear Circles

查看:88
本文介绍了出现消失的圈子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个圈子.它会出现在表格的正中间.
几秒钟后,它会消失.它将出现在右侧(从中心开始),间隙恰好为5英寸.像左侧5英寸间隙一样

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

推荐答案

处理Form Paint事件,并向您的表单添加一个Timer.
将Timer设置为几秒钟的间隔(Interval属性以milliseconnds表示,因此1000是一秒钟),并处理timer Tick事件.
向您的表单类添加一个变量,int暂时可以,但是枚举会更好.
在Tick事件处理程序中,将变量的值增加1,然后调用Invalidate方法.
在Paint事件中,检查以4为模的变量的值-这将使值介于0和3之间(含0和3).
如果为0,则不要画任何东西
如果为1,请在中间画圆.
如果是2,请向左画圆.
如果是3,请向右画圆.

您可以使用处理程序中提供的e.Graphics上下文并通过调用其
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);

这将画出您的圆形,水平居中.

由于屏幕尺寸各不相同,因此您将不得不用左右圆圈的位置来进行游戏,因此很难解决向左5英寸"的移动.


以上代码不起作用?
我有3张图片(图片1,图片2,图片3),

使用间隔值为5000(即5秒,I
)的计时器控件 要完成以下任务:

-最初,用户只能在表单中间看到Image1,即2张图像
设置为不可见.
-加载表单时出现image1
出现在表格的正中间
-5秒钟后,图像1消失,图像2出现在右侧.
-5秒钟后,image2消失而image3出现在左侧
-5秒钟后,image3消失,image1出现

我在设计中将计时器控件的Enable属性设置为"True"
时间.
我将计时器控件的Interval属性值设置为5000 in
设计时间.

我假设我已完成所有编码,但仅显示两个图像而不工作


有人可以帮我编写我想完成的工作吗?"


首先,检查您是否正在处理计时器滴答"事件-突出显示计时器,然后在属性窗格中查看,单击事件"按钮(看起来像是闪电),然后检查滴答"事件.如果没有处理程序,请双击创建一个处理程序.

在事件处理程序方法中,您将需要:
类级别的模式"变量:

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:

private enum ShowImage
    {
    FirstOnly,
    SecondOnly,
    ThirdOnly,
    }
private ShowImage showWhichImage = ShowImage.FirstOnly;


在处理程序方法中,您可以使用此方法确定接下来要显示的内容:


In the handler method, you use this to determine what to show next:

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());
    }


这篇关于出现消失的圈子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆