c#图像从A移动到B [英] c# Image moving from A to B

查看:132
本文介绍了c#图像从A移动到B的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是C#的新手,我想在我当前的项目中加入一个新的部分。



实际上我做了一个表格使用计时器和一些按钮来启动/暂停标签中显示的时间。



现在我要做的是制作一个2D画布,其图像在A(由左)移动到B(右)在由之前创建的计时器刻度。



IE:当我点击开始按钮时,程序开始计算计时器标签中的时间并将图像从A移动到B.当图像到达B时,计时器停止。





请帮我编写这部分代码?



感谢任何帮助,谢谢!

Hi all, I'm new to C# and I'd like to include a new part inside my current project.

Actually I've done a form with a Timer and some buttons that start/pause the time displayed in a label.

Now what I'd like to do is make a 2D canvas with an image that moves from A (left) to B (right) on a line controlled by the timer tick created before.

IE: When I click on the start button, the program starts counting the time in the timer label and moving the image from A to B. When the image arrives at B, the timer stops.


Please can you help me coding this part?

Any help is appreciate, thanks!

推荐答案

您好



只是一个样本: -



Hi

Just a sample :-

Timer _timer = new Timer();
int _xfinal = 250;

private void btnStart_Click(object sender, EventArgs e)
{
    _timer.Interval = 100;
    _timer.Tick += _timer_Tick;
    _timer.Enabled = true;
    _timer.Start();
}

void _timer_Tick(object sender, EventArgs e)
{
    MoveObject();
}

private void MoveObject()
{
    int x = lblGO.Location.X;
    int y = lblGO.Location.Y;
    lblGO.Location = new Point(x + 1, y);

    if (x == _xfinal) _timer.Stop();
}









问候

Dominic Abraham





Regards
Dominic Abraham


Timer _timer = new Timer();
        int _xfinal = 250;

        private void btnStart_Click(object sender, EventArgs e)
        {
            _timer.Interval = 100;
            _timer.Tick += _timer_Tick;
            _timer.Enabled = true;
            _timer.Start();
        }

        void _timer_Tick(object sender, EventArgs e)
        {
            MoveObject();
        }

        private void MoveObject()
        {
            int x = lblGO.Location.X;
            int y = lblGO.Location.Y;
            lblGO.Location = new Point(x + 1, y);

            if (x == _xfinal) _timer.Stop();
        }


这篇关于c#图像从A移动到B的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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