目的是每隔一段时间,从新绘制下,怎么一直包参数错误, OnPaint里面绘制没有问题,我用定时绘制,怎么包错。 谢谢大虾帮忙看下。 要做的效果就是移动文字和图片(所以继承了PictureBox,其实用Panle,Control都可以的,)。这里先做个文字的测试。 因为要移动的大小可是0.2,这样。开始我只是改变控件的位置,可是那个最小的是1,在移动的时候一点不连续,明显能看出的。 所以自己绘制一下。代码如下:
public class DrawStringControl : PictureBox
{
float moveSize = 0.5F;
float CurrentPost = -10F;
private Graphics g;//
public DrawStringControl()
{
timer1 = new Timer();
timer1.Interval = Interval;
timer1.Tick +=new EventHandler(timer1_Tick);
}
private Timer timer1;
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
g = pe.Graphics;
PointF p = new PointF(CurrentPost,0F);//
g.DrawString(Value, new Font("宋体", 15), Brushes.Red, p);
}
/// <summary>
/// 开始滚动
/// </summary>
public void Start()
{
timer1.Start();
} public void Stop()
{
timer1.Stop();
}
/// <summary>
/// 向上移动的大小
/// </summary>
public float MoveSize
{
get { return moveSize; }
set { moveSize = value; }
} private int interval = 10;
/// <summary>
/// 多长时间移动一次
/// </summary>
public int Interval
{
get { return interval; }
set { interval = value; }
}
private void timer1_Tick(object sender, EventArgs e)
{
CurrentPost -= moveSize;
PointF p = new PointF(CurrentPost, 0F);//左移动
g.DrawString(Value, new Font("宋体", 12), Brushes.Red, p);
} private string value;
/// <summary>
/// 要画的文本
/// </summary>
public string Value
{
get { return this.value; }
set
{
this.value = value;
}
}
}
public class DrawStringControl : PictureBox
{
float moveSize = 0.5F;
float CurrentPost = -10F;
private Graphics g;//
public DrawStringControl()
{
timer1 = new Timer();
timer1.Interval = Interval;
timer1.Tick +=new EventHandler(timer1_Tick);
}
private Timer timer1;
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
g = pe.Graphics;
PointF p = new PointF(CurrentPost,0F);//
g.DrawString(Value, new Font("宋体", 15), Brushes.Red, p);
}
/// <summary>
/// 开始滚动
/// </summary>
public void Start()
{
timer1.Start();
} public void Stop()
{
timer1.Stop();
}
/// <summary>
/// 向上移动的大小
/// </summary>
public float MoveSize
{
get { return moveSize; }
set { moveSize = value; }
} private int interval = 10;
/// <summary>
/// 多长时间移动一次
/// </summary>
public int Interval
{
get { return interval; }
set { interval = value; }
}
private void timer1_Tick(object sender, EventArgs e)
{
CurrentPost -= moveSize;
PointF p = new PointF(CurrentPost, 0F);//左移动
g.DrawString(Value, new Font("宋体", 12), Brushes.Red, p);
} private string value;
/// <summary>
/// 要画的文本
/// </summary>
public string Value
{
get { return this.value; }
set
{
this.value = value;
}
}
}
private void timer1_Tick(object sender, EventArgs e)
{
CurrentPost -= moveSize;
PointF p = new PointF(CurrentPost, 0F);//左移动
g.DrawString(Value, new Font("宋体", 12), Brushes.Red, p); 这里报错
}目的就是每隔一段时间绘制一下,这个该怎么弄? 最关键的是不知道在哪里绘制,现在除了在OnPaint 里面,在其他方法你们该怎么绘制呢?