| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1161 人关注过本帖
标题:用C#实现多张图片平行移动,图片一直循环的核心算法
只看楼主 加入收藏
a2563s
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-10-26
结帖率:0
收藏
已结贴  问题点数:20 回复次数:4 
用C#实现多张图片平行移动,图片一直循环的核心算法
用C#实现多张图片平行移动,图片一直循环的核心算法 求指教
搜索更多相关主题的帖子: 算法 图片 
2012-10-31 22:56
wangnannan
Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18
等 级:贵宾
威 望:87
帖 子:2546
专家分:9359
注 册:2007-11-3
收藏
得分:5 
跑马灯 平行移动 就是控制location x坐标

出来混,谁不都要拼命的嘛。 。拼不赢?那就看谁倒霉了。 。有机会也要看谁下手快,快的就能赢,慢。 。狗屎你都抢不到。 。还说什么拼命?
2012-11-01 10:17
跳过去
Rank: 8Rank: 8
等 级:贵宾
威 望:20
帖 子:282
专家分:976
注 册:2012-8-13
收藏
得分:5 
.....

光棍中.....
2012-11-01 16:07
zwffff
Rank: 4
等 级:业余侠客
威 望:1
帖 子:58
专家分:224
注 册:2007-11-13
收藏
得分:5 
以下是引用wangnannan在2012-11-1 10:17:21的发言:

跑马灯 平行移动 就是控制location x坐标

参照此版主所说。

欢迎加入.Net技术交流群:90925122
2012-11-04 15:31
mmxo
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:13
帖 子:189
专家分:1090
注 册:2012-11-7
收藏
得分:5 
给你一个范例代码,因为不知道怎么发图片,所以如果要看UI图片或FormMain.Designer.cs请到http://www.中查找相关帖子查看,核心算法就在Timer触发的那一段。
程序代码:
using System;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using Timer = System.Threading.Timer;

namespace ImageCycleMove
{
    public partial class FormMain : Form
    {
        #region 只读全局字段

        private readonly Timer _timer;

        #endregion

        #region 全局字段

        private int             _changeCritical;
        private int             _left;
        private int             _leftPictureBoxIndex;
        private PictureBox[]    _pictureBoxs;

        #endregion

        #region 构造函数

        public FormMain()
        {
            InitializeComponent();
            _timer = new Timer(TimerProcess, null, Timeout.Infinite, Timeout.Infinite);
            Closing                     += FormMain_Closing;
            NudImageCount.ValueChanged  += StartCycleMove;
            NudImageMargin.ValueChanged += StartCycleMove;
            NudInterval.ValueChanged    += NudInterval_ValueChanged;
            SizeChanged                 += StartCycleMove;
        }
      
        #endregion

        #region 控件事件

        void ButStop_Click(object sender, EventArgs e)
        {
            _timer.Change(Timeout.Infinite, Timeout.Infinite);
            ButStop.Enabled  = false;
            ButStart.Enabled = true;
        }

        void FormMain_Closing(object sender,  e)
        {
            _timer.Change(Timeout.Infinite, Timeout.Infinite);
        }

        void NudInterval_ValueChanged(object sender, EventArgs e)
        {
            _timer.Change(0, (int)NudInterval.Value);
        }

        void StartCycleMove(object sender, EventArgs e)
        {
            StartCycleMoveProcess();
        }

        #endregion

        #region 事件处理

        void TimerProcess(object o)
        {
            try
            {
                if (InvokeRequired)
                    Invoke(new Action<object>(TimerProcess), new[] { o });
                else
                {
                    _left--;
                    foreach (var pictureBox in _pictureBoxs)
                        pictureBox.Left--;
                    if (_left < _changeCritical)
                    {
                        _left = 0;
                        var pictureBox = _pictureBoxs[_leftPictureBoxIndex];
                        pictureBox.Left = Panel.Width + (int)NudImageMargin.Value;
                        _leftPictureBoxIndex++;
                        if (_leftPictureBoxIndex >= (int)NudImageCount.Value)
                            _leftPictureBoxIndex = 0;
                    }
                }
            }
            catch { }
        }

        #endregion

        #region 私有方法

        private void CreateImages()
        {
            var imageCount      = (int) NudImageCount.Value;
            var imageMargin     = (int) NudImageMargin.Value;
            var containerWidth  = Panel.Width;
            var eachImageWidth  = (containerWidth - (imageCount - 2) * imageMargin) / (imageCount - 1);
            var eachImageHeight = Panel.Height;
            _changeCritical     = -(eachImageWidth + imageMargin);
            _pictureBoxs        = new PictureBox[imageCount];
            for (var i = 0; i < imageCount; i++)
            {
                var bitmap = new Bitmap(eachImageWidth, eachImageHeight);
                var random = new Random(DateTime.Now.Millisecond);
                var g = Graphics.FromImage(bitmap);
                var backColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
                g.Clear(backColor);
                g.DrawString("", new Font("SimHei", 10f),
                             new SolidBrush(Color.FromArgb(255 - backColor.R, 255 - backColor.R, 255 - backColor.R)), 5, 5);
                g.DrawString(i.ToString("00"), new Font("SimHei", eachImageWidth / 4f, FontStyle.Bold),
                             new SolidBrush(Color.FromArgb(255 - backColor.R, 255 - backColor.R, 255 - backColor.R)), 5, 15);
                var pictureBox = new PictureBox
                                     {
                                         Width    = eachImageWidth,
                                         Height   = eachImageHeight,
                                         Image    = bitmap,
                                         Location = new Point(i * eachImageWidth + i * imageMargin, 0)
                                     };
                _pictureBoxs[i] = pictureBox;
                Panel.Controls.Add(pictureBox);
            }
        }

        private void StartCycleMoveProcess()
        {
            ButStart.Enabled = false;
            Panel.Controls.Clear();
            _left = 0;
            _leftPictureBoxIndex = 0;
            CreateImages();
            _timer.Change(0, (int)NudInterval.Value);
            ButStop.Enabled = true;
        }

        #endregion




[ 本帖最后由 mmxo 于 2012-11-7 16:32 编辑 ]

为提高中华编程水平而奋斗
2012-11-07 16:30
快速回复:用C#实现多张图片平行移动,图片一直循环的核心算法
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016978 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved