C# winform的图片滚动

小李所属 2009-12-15 02:48:08
如何在winform图片框里的加载多张图片,并让他们像网页上走马灯一样滚动?是左右滚动啊!麻烦哪个高手 指教
...全文
1742 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
lmllouk 2010-05-14
  • 打赏
  • 举报
回复
正需要呢
不老神仙 2010-03-12
  • 打赏
  • 举报
回复
学习学习 现在也正因为这个头痛
wuyq11 2009-12-16
  • 打赏
  • 举报
回复
Bitmap bmp;
Timer timer = new Timer();
int top = 0;
public Form1()
{
this.Size = new Size(300, 300);
Rectangle r= this.ClientRectangle;
bmp= new Bitmap(r.Width, r.Height * 2);
using (Graphics g = Graphics.FromImage(bmp))
{
g.Clear(Color.LightBlue);
Random ran= new Random();
for (int i = 0; i < 1000; i++)
{
int x = ran.Next() % bmp.Width;
int y = ran.Next() % bmp.Height;
int i= ran.Next() % 5;
g.FillEllipse(Brushes.White, x, y, dot, dot);
g.FillEllipse(Brushes.White, x, y+r.Height, i, i);
}
}
timer.Interval = 200;
timer.Enabled = true;
timer.Tick += delegate { Invalidate(); };
}
protected override void OnPaint(PaintEventArgs e)
{
int height = this.ClientRectangle.Height;
top += 10;
if (top > height) top = 0;
e.Graphics.DrawImageUnscaled(bmp, 0, top - height);
}
protected override void OnPaintBackground(PaintEventArgs e)
{
}

wartim 2009-12-15
  • 打赏
  • 举报
回复
红、绿、蓝三张图不停切换



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

namespace WindowsApplication226
{
public partial class Form1 : Form
{
PictureBox PB = new PictureBox();
int Pos = 0;
int CurrentBmpIndex = 0;
Bitmap[] Bmps = new Bitmap[3];

public Form1()
{
InitializeComponent();

Bmps[0] = new Bitmap(100, 100);
using (Graphics G = Graphics.FromImage(Bmps[0]))
G.Clear(Color.Red);

Bmps[1] = new Bitmap(100, 100);
using (Graphics G = Graphics.FromImage(Bmps[1]))
G.Clear(Color.Green);

Bmps[2] = new Bitmap(100, 100);
using (Graphics G = Graphics.FromImage(Bmps[2]))
G.Clear(Color.Blue);

PB.Parent = this;
PB.Size = new Size(100, 100);
PB.Image = Bmps[0];

CurrentBmpIndex = 0;
Pos = 100;

Timer T = new Timer();
T.Interval = 10;
T.Tick += new EventHandler(T_Tick);
T.Enabled = true;
}

void T_Tick(object sender, EventArgs e)
{
if (++Pos > 100)
{
CurrentBmpIndex = (CurrentBmpIndex + 1) % 3;
Pos = 0;
}

Bitmap Temp =new Bitmap (100,100);

using (Graphics G = Graphics.FromImage(Temp))
{
G.DrawImage(PB.Image, new Rectangle(-1, 0, 100, 100));
G.DrawImage(Bmps[CurrentBmpIndex], new Rectangle(99, 0, 100, 100));
}

PB.Image = Temp;
}
}
}
小李所属 2009-12-15
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 deyter 的回复:]
http://topic.csdn.net/u/20090925/10/1fc69a43-8f6e-41c6-9e78-3ce8f1db4134.html
这个帖子是我问在winform中图片滚动效果的
[/Quote]

可以把图片放到正中间吗?
小李所属 2009-12-15
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 cstester 的回复:]
把一些图片放在FlowLayoutPanel 容器中。( 设置好图片的边距等等)最后只需要调FlowLayoutPanel的x轴或者y轴的坐标即可。

如果想要动态效果可以放在timer tick事件里。。
代码:

[code=C#]
int x=0;
private void timer1_Tick(object sender, EventArgs e)
{
        x--;
        flpanel.Location = new Point(x,flpanel.Location.Y);
}

code]
[/Quote]
有完整的代码没啊!
cstester 2009-12-15
  • 打赏
  • 举报
回复
把一些图片放在FlowLayoutPanel 容器中。( 设置好图片的边距等等)最后只需要调FlowLayoutPanel的x轴或者y轴的坐标即可。

如果想要动态效果可以放在timer tick事件里。。
代码:

[code=C#]
int x=0;
private void timer1_Tick(object sender, EventArgs e)
{
x--;
flpanel.Location = new Point(x,flpanel.Location.Y);
}

code]
deyter 2009-12-15
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20090925/10/1fc69a43-8f6e-41c6-9e78-3ce8f1db4134.html
这个帖子是我问在winform中图片滚动效果的
deyter 2009-12-15
  • 打赏
  • 举报
回复
建议用双缓冲来绘图,直接改变控件位置会不流畅。
小李所属 2009-12-15
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 dylike 的回复:]
一个控件里加载很多图片?是同时只能显示一张图还是同时显示所有图片?两种效果做起来也不一样.
[/Quote]
是显示多张图片啊!图片在不停的滚动 然后就 按 抽签这个 按钮 随机选 滚动的 图片
dylike 2009-12-15
  • 打赏
  • 举报
回复
一个控件里加载很多图片?是同时只能显示一张图还是同时显示所有图片?两种效果做起来也不一样.
Hamsic 2009-12-15
  • 打赏
  • 举报
回复
this.pictureBox1.Location = new Point(this.pictureBox1.Location.X + 1, 17);
wyfde123 2009-12-15
  • 打赏
  • 举报
回复
可以在代码中操作控件的Location属性。
cicigl 2009-12-15
  • 打赏
  • 举报
回复
UPUP

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧