日期:2014-05-17 浏览次数:21178 次
Action 委托方法 = () => { 移动字幕.Left = 移动字幕.Left - 1; if (移动字幕.Right < 0) 移动字幕.Left = this.Width; };
委托方法();
------解决方案--------------------
添加以下类至代码页:
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
public class ScrollStringLib
{
private Control _Ct;
private Color _TextColor;
private Bitmap _TextLayer;
private System.Timers.Timer withEventsField__Timer = new System.Timers.Timer();
private System.Timers.Timer _Timer {
get { return withEventsField__Timer; }
set {
if (withEventsField__Timer != null) {
withEventsField__Timer.Elapsed -= _Timer_Elapsed;
}
withEventsField__Timer = value;
if (withEventsField__Timer != null) {
withEventsField__Timer.Elapsed += _Timer_Elapsed;
}
}
}
private int _ScrollnIndex = 0;
private Bitmap _tempBmp;
public void ScrollStop()
{
_Timer.Stop();
}
public void ScrollStart(Control Ct, string Text, Color TextColor, int Speed)
{
_Ct = Ct;
if (_TextLayer != null)
_TextLayer.Dispose();
Size Sz = Ct.CreateGraphics.MeasureString(Text, _Ct.Font, _Ct.Width).ToSize;
Sz = new Size(Sz.Width + 10, Sz.Height + 10);
_TextLayer = new Bitmap(Sz.Width, Sz.Height);
using (Graphics G = Graphics.FromImage(_TextLayer)) {
G.DrawString(Text, _Ct.Font, new SolidBrush(TextColor), new Rectangle(0, 0, Sz.Width, Sz.Height));
}
_Timer.Interval = Speed;
_Timer.Start();
}
private void _Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try {
if (_tempBmp != null)
_tempBmp.Dispose();
_tempBmp = new Bitmap(_Ct.Width, _Ct.Height);
using (Graphics G = Graphics.FromImage(_tempBmp)) {
_ScrollnIndex -= 1;
if (_TextLayer != null) {
if (_ScrollnIndex <= -_TextLayer.Height)
_ScrollnIndex = 0;
G.DrawImage(_TextLayer, new Rectangle(0, _ScrollnIndex, _Ct.Width, _Ct.Height), new Rectangle(0, 0, _Ct.Width, _Ct.Height), GraphicsUnit.Pixel);
}
}
_Ct.BackgroundImage = _tempBmp;
} catch {
}
}
}
------解决方案--------------------