• 大小: 55KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-28
  • 语言: C#
  • 标签: 图片移动  C#移动  

资源简介

添加图片实现图片移动,加速减速上下左右环周窗口变大变小

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WPictureMove
{
    public partial class Form1 : Form
    {
        int a=1;//指定图片在哪个边上运动,1:上边,2:右边,3:下边,4:左边

        int style = 0;//指定运动方式,1:左右,2:上下,3:环周

        int step = 1;//步长

        int direct = 1;//变向

        int i = 1;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender EventArgs e)//环周
        {
            timer1.Enabled = true;
            style = 3;
            pictureBox1.Left = 0;
            pictureBox1.Top = 0;

        }
       
        private void timer1_Tick(object sender EventArgs e)//运动控制器
        {
            btnStop.Enabled = true;
            label1.Text = “当前位置:(“ + pictureBox1.Left + “,“ + pictureBox1.Top + “)“;
            switch (style)
            {
                case 1:
                    {
                        this.Text = “正在左右移动,每移动1像素用时“ + timer1.Interval + “毫秒“;
                        pictureBox1.Left += step * direct ;
                        if (pictureBox1.Left > this.Width - pictureBox1.Width)
                        {
                            direct = -1;
                        }
                        if (pictureBox1.Left < 0)
                        {
                            direct = 1;
                        }

                    }
                    break;

                case 2:
                    {
                        this.Text = “正在上下移动,每移动1像素用时“ + timer1.Interval + “毫秒“;
                        pictureBox1.Top += step * direct ;
                        if (pictureBox1.Top > this.Height - pictureBox1.Height)
                        {
                            direct = -1;
                        }
                        if (pictureBox1.Top < 0)
                        {
                            direct = 1;
                        }

                    }
                    break;

                case 3:
                    {
                        this.Text = “正在环周移动,每移动1像素用时“ + timer1.Interval + “毫秒“;
                        if (a == 1)//上边
                        {
                            if (pictureBox1.Left < this.Width - pictureBox1.Width)
                            {
                                pictureBox1.Left += step;
                            }
                            else
                            {
                                a = 2;
                            }
                        }
                        if (a == 2)//右边
                        {
                            if (pictureBox1.Top < this.Height - pictureBox1.Height-30)
                            {
                                pictureBox1.Top += step;
                            }
               

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      16384  2018-10-08 11:43  WPictureMove\WPictureMove\bin\Debug\WPictureMove.exe

     文件      32256  2018-10-08 11:43  WPictureMove\WPictureMove\bin\Debug\WPictureMove.pdb

     文件      14328  2018-10-11 19:11  WPictureMove\WPictureMove\bin\Debug\WPictureMove.vshost.exe

     文件        490  2017-10-29 16:42  WPictureMove\WPictureMove\bin\Debug\WPictureMove.vshost.exe.manifest

     文件       7890  2018-10-08 11:43  WPictureMove\WPictureMove\Form1.cs

     文件       9770  2018-10-08 11:43  WPictureMove\WPictureMove\Form1.Designer.cs

     文件      10089  2018-10-08 11:43  WPictureMove\WPictureMove\Form1.resx

     文件       1390  2018-10-11 19:11  WPictureMove\WPictureMove\obj\Debug\WPictureMove.csproj.FileListAbsolute.txt

     文件        847  2018-10-08 11:43  WPictureMove\WPictureMove\obj\Debug\WPictureMove.csproj.GenerateResource.Cache

     文件      16384  2018-10-08 11:43  WPictureMove\WPictureMove\obj\Debug\WPictureMove.exe

     文件       3011  2018-10-08 11:43  WPictureMove\WPictureMove\obj\Debug\WPictureMove.Form1.resources

     文件      32256  2018-10-08 11:43  WPictureMove\WPictureMove\obj\Debug\WPictureMove.pdb

     文件        180  2018-09-19 15:29  WPictureMove\WPictureMove\obj\Debug\WPictureMove.Properties.Resources.resources

     文件        493  2018-09-19 15:15  WPictureMove\WPictureMove\Program.cs

     文件       1380  2018-09-19 15:15  WPictureMove\WPictureMove\Properties\AssemblyInfo.cs

     文件       2874  2018-09-19 15:15  WPictureMove\WPictureMove\Properties\Resources.Designer.cs

     文件       5612  2018-09-19 15:15  WPictureMove\WPictureMove\Properties\Resources.resx

     文件       1097  2018-09-19 15:15  WPictureMove\WPictureMove\Properties\Settings.Designer.cs

     文件        249  2018-09-19 15:15  WPictureMove\WPictureMove\Properties\Settings.settings

     文件       3770  2018-09-19 15:29  WPictureMove\WPictureMove\WPictureMove.csproj

     文件        926  2018-09-19 15:15  WPictureMove\WPictureMove.sln

    ..A..H.     19968  2018-10-11 19:12  WPictureMove\WPictureMove.suo

     目录          0  2018-09-25 10:50  WPictureMove\WPictureMove\obj\Debug\Refactor

     目录          0  2018-09-19 15:15  WPictureMove\WPictureMove\obj\Debug\TempPE

     目录          0  2018-09-19 15:29  WPictureMove\WPictureMove\bin\Debug

     目录          0  2018-10-08 11:43  WPictureMove\WPictureMove\obj\Debug

     目录          0  2018-09-19 15:15  WPictureMove\WPictureMove\bin

     目录          0  2018-09-19 15:15  WPictureMove\WPictureMove\obj

     目录          0  2018-09-19 15:15  WPictureMove\WPictureMove\Properties

     目录          0  2018-10-08 11:43  WPictureMove\WPictureMove

............此处省略4个文件信息

评论

共有 条评论