static int iW, iInterval, i,k,n; private void button1_Click_1(object sender, EventArgs e)
{
iInterval = 3;
i = iInterval;
iW = 10;
k = 0;
n = 0;
timer2.Interval = 100;
this.timer2.Start(); } private void timer2_Tick(object sender, EventArgs e)
{
if (i < iW)
{
if (k == 0)
twinraster(Color.White, Color.Black,Color.Red, i, 0, 0, this.pictureBox1.Width, 0, iW);
else if(k==1)
twinraster(Color.Red, Color.White, Color.Black, i, 0, 0, this.pictureBox1.Width, 0, iW);
else
twinraster(Color.Black, Color.Red, Color.White, i, 0, 0, this.pictureBox1.Width, 0, iW); i += iInterval;
}
else
{
i = i - iW + 1;
if (k == 0)
{
k = 1;
n = 0;
return;
}
if (k == 1)
{
if (n == 0)
k = 2;
else
k = 0;
return;
}
if (k == 2)
{
k = 1;
n = 1;
}
//twinraster(Color.White, Color.Black, i, 0, 0, this.pictureBox1.Width, 0, iW);
}
}private void twinraster(Color cColor1, Color cColor2,Color cColor3, int ist, int iX1, int iY1, int iX2, int iY2, int iWidth)//画三色光栅
{
Pen pen1 = new Pen(cColor1, iWidth);
Pen pen2 = new Pen(cColor2, iWidth);
Pen pen3 = new Pen(cColor1, ist);
Pen pen4 = new Pen(cColor3, iWidth); Graphics myGraphics = this.pictureBox1.CreateGraphics(); myGraphics.DrawLine(pen3, iX1, 0, iX2, 0); iY1 = ist;
iY2 = ist; for (; iY1 <= this.pictureBox1.Height; iY1 += iWidth, iY2 += iWidth)
{
myGraphics.DrawLine(pen2, iX1, iY1, iX2, iY2);
iY1 += iWidth;
iY2 += iWidth;
myGraphics.DrawLine(pen4, iX1, iY1, iX2, iY2);
iY1 += iWidth;
iY2 += iWidth;
myGraphics.DrawLine(pen1, iX1, iY1, iX2, iY2);
}
myGraphics.DrawLine(pen2, iX1, iY1, iX2, iY2);
}我是这样写的,但是算法的效率肯定很差,而且在移动的时候,有一个地方会出错,颜色没控制得好,我已经弄了好久都没解决这个问题。主要是自己的算法已经一塌糊涂了,望知道的朋友帮忙看一下,谢谢了
{
iInterval = 3;
i = iInterval;
iW = 10;
k = 0;
n = 0;
timer2.Interval = 100;
this.timer2.Start(); } private void timer2_Tick(object sender, EventArgs e)
{
if (i < iW)
{
if (k == 0)
twinraster(Color.White, Color.Black,Color.Red, i, 0, 0, this.pictureBox1.Width, 0, iW);
else if(k==1)
twinraster(Color.Red, Color.White, Color.Black, i, 0, 0, this.pictureBox1.Width, 0, iW);
else
twinraster(Color.Black, Color.Red, Color.White, i, 0, 0, this.pictureBox1.Width, 0, iW); i += iInterval;
}
else
{
i = i - iW + 1;
if (k == 0)
{
k = 1;
n = 0;
return;
}
if (k == 1)
{
if (n == 0)
k = 2;
else
k = 0;
return;
}
if (k == 2)
{
k = 1;
n = 1;
}
//twinraster(Color.White, Color.Black, i, 0, 0, this.pictureBox1.Width, 0, iW);
}
}private void twinraster(Color cColor1, Color cColor2,Color cColor3, int ist, int iX1, int iY1, int iX2, int iY2, int iWidth)//画三色光栅
{
Pen pen1 = new Pen(cColor1, iWidth);
Pen pen2 = new Pen(cColor2, iWidth);
Pen pen3 = new Pen(cColor1, ist);
Pen pen4 = new Pen(cColor3, iWidth); Graphics myGraphics = this.pictureBox1.CreateGraphics(); myGraphics.DrawLine(pen3, iX1, 0, iX2, 0); iY1 = ist;
iY2 = ist; for (; iY1 <= this.pictureBox1.Height; iY1 += iWidth, iY2 += iWidth)
{
myGraphics.DrawLine(pen2, iX1, iY1, iX2, iY2);
iY1 += iWidth;
iY2 += iWidth;
myGraphics.DrawLine(pen4, iX1, iY1, iX2, iY2);
iY1 += iWidth;
iY2 += iWidth;
myGraphics.DrawLine(pen1, iX1, iY1, iX2, iY2);
}
myGraphics.DrawLine(pen2, iX1, iY1, iX2, iY2);
}我是这样写的,但是算法的效率肯定很差,而且在移动的时候,有一个地方会出错,颜色没控制得好,我已经弄了好久都没解决这个问题。主要是自己的算法已经一塌糊涂了,望知道的朋友帮忙看一下,谢谢了
解决方案 »
- 这两个button事件怎么不听使唤啊
- 内存泄漏问题
- word 中添加文件作为一个附件?
- winform如何完整获取数据库表结构,并显示在textbox中?
- 各位高手,帮忙!
- 为什么总说INSERT INTO 语法错误 “/myweb”应用程序中的服务器错误。
- ICollection 序列化问题,希望高手帮忙解决,倾其所有给分
- 在ACCESS中如果用自动编号的类型作为主键,则更新时就会产生并发冲突错误,有谁知道怎样解决这个问题
- 关于windows pocket pc 或windows ce.net环境下,安装部署程序的问题
- 怎样把form中的东西引用到新的class中
- C#winform怎么实现QQ的那种表情列表?
- ConfigurationSettings.AppSettings问题
private void timer1_Tick(object sender, EventArgs e)
{
yOffset = (yOffset + speed) % (lineHeight * lineColors.Length);
pictureBox1.Refresh();
}private void button1_Click(object sender, EventArgs e)
{
timer2.Enabled = !timer2.Enabled;
}/// <summary>
/// 线的高度
/// </summary>
private int lineHeight = 10;
/// <summary>
/// 线条的颜色
/// </summary>
private Color[] lineColors = new Color[] {
Color.White, Color.Black, Color.Red, Color.Green };
/// <summary>
/// 横向偏移
/// </summary>
private int yOffset = 0;
/// <summary>
/// 滚动的速度
/// </summary>
private int speed = 2;/// <summary>
/// 绘制全部线条
/// </summary>
/// <param name="AGraphics">绘制的画布</param>
private void DrawFace(Graphics AGraphics)
{
int vIndex = 0; // 向下绘制
for (int y = yOffset; y < AGraphics.ClipBounds.Height; y += lineHeight)
{
AGraphics.FillRectangle(new SolidBrush(lineColors[vIndex]),
new RectangleF(0, y, AGraphics.ClipBounds.Width, lineHeight));
vIndex = (vIndex + 1) % lineColors.Length;
} vIndex = lineColors.Length - 1; // 向上绘制
for (int y = yOffset - lineHeight; y >= -lineHeight; y -= lineHeight)
{
vIndex = (vIndex + 1) % lineColors.Length;
AGraphics.FillRectangle(new SolidBrush(
lineColors[lineColors.Length - vIndex - 1]),
new RectangleF(0, y, AGraphics.ClipBounds.Width, lineHeight));
}
}private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
DrawFace(e.Graphics);
}