小弟正在做一个项目,老总要求在界面上实现一个动画的线条效果,大致意思如下: ---------------------------
| |
| |
| |
| |按上面这个路径,用一个红色带拖尾的线条,从左向右或从右向左运动,就像Flash里面那种边框流动效果!!要是拖尾难做,不带拖尾也行,只要线条能流动就行!!小弟完全没有头绪,想上网搜又不知该怎么搜,抓狂中小弟刚找到这份工作,现在找工作这么难,万望各位老大帮忙啊,解决了另有分送上,谢谢谢谢啦!
| |
| |
| |
| |按上面这个路径,用一个红色带拖尾的线条,从左向右或从右向左运动,就像Flash里面那种边框流动效果!!要是拖尾难做,不带拖尾也行,只要线条能流动就行!!小弟完全没有头绪,想上网搜又不知该怎么搜,抓狂中小弟刚找到这份工作,现在找工作这么难,万望各位老大帮忙啊,解决了另有分送上,谢谢谢谢啦!
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication3
{
public partial class Form1 : Form
{
private int i_localprama; //控制位置参数
private Pen p_Ground; //底色
private Pen p_Current; //当前色 public Form1()
{
InitializeComponent();
this.i_localprama = 0;
this.p_Ground = new Pen(Brushes.Black, 2);
this.p_Current = new Pen(Brushes.Red, 4);
} private void Form1_Load(object sender, EventArgs e)
{
this.timer1.Start();
} private void panel1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawLine(this.p_Ground, 0, 20, i_localprama, 20);
e.Graphics.DrawLine(this.p_Current, i_localprama, 20, i_localprama + 4, 20);
} private void timer1_Tick(object sender, EventArgs e)
{
this.i_localprama++;
this.panel1.Refresh();
}
}
}
建议lz用flash做,然后在c#中用控件加载flash。点击看看这个c#与flash交互编程的,呵呵
— —
— —
— —
— —
— —
— —
— —
— —
— —
— —using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication58
{
public partial class Form1 : Form
{
Timer T = new Timer();
int[,] Lines = new int[2, 10];
Bitmap OrgBmp = null; public Form1()
{
InitializeComponent();
this.Controls.Clear(); OrgBmp = new Bitmap(300, 300);
Graphics G = Graphics.FromImage(OrgBmp);
G.FillRectangle(new SolidBrush(this.BackColor), new Rectangle(0, 0, 300, 300));
G.Dispose(); for (int i = 0; i < 10; i++)
Lines[0, i] = Lines[1, i] = i * 10; T.Interval = 100;
T.Tick += new EventHandler(T_Tick);
T.Enabled = true;
} void T_Tick(object sender, EventArgs e)
{
Bitmap CacheBmp = new Bitmap(OrgBmp);
Graphics G = Graphics.FromImage(CacheBmp);
for (int i = 0; i < 10; i++)
{
Lines[0, i] = Lines[0, i] - 1 < 0 ? 90 : Lines[0, i] - 1;
Lines[1, i] = (Lines[1, i] + 1) % 90;
G.DrawLine(new Pen(new SolidBrush(Color.Red)), new Point(0, Lines[0, i]), new Point(30, Lines[0, i]));
G.DrawLine(new Pen(new SolidBrush(Color.Green)), new Point(100, Lines[1, i]), new Point(130, Lines[1, i]));
}
G.Dispose();
G = this.CreateGraphics();
G.DrawImage(CacheBmp, new Point(0, 0));
G.Dispose();
}
}
}
那是因为每次都new了一个bitmap,如果你不想等自动垃圾回收,就强制垃圾回收一下内存就不会涨了 void T_Tick(object sender, EventArgs e)
{
Bitmap CacheBmp = new Bitmap(OrgBmp);
...
GC.Collect();
}