前几天处理一个比较有意思的需求,客户要求在屏幕滚动显示一些提示信息,而同时还要考虑到客户做交易时的屏幕刷新问题,屏幕刷新后滚动信息不能重新开始,而是继续刷新前的操作。
这样一来就无法使用javascript的走马灯【marquee】效果了。为了不对已有程序做太大改动,无奈之下只好写一外挂,专门做滚动字幕显示。现将源码公开,以方便有相同需要的朋友。
该程序设计有几点需要注意:
(1)创建Form时应该override CreateParams CreateParams
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x8000000; //使其在创建时处于非激活状态
return cp;
}
}
(2)创建时设置Form属性
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
//设置窗体属性
this.BackColor = Color.Fuchsia;
this.TransparencyKey = Color.Fuchsia;
this.TopMost = true; //置顶
//this.WindowState = FormWindowState.Maximized;
this.ShowInTaskbar = false; //取消在任务栏中显示
this.FormBorderStyle = FormBorderStyle.None;//取消标题栏、边框等
//this.StartPosition = FormStartPosition.CenterScreen;//窗体位置
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
/// <summary>
/// 在主屏显示
/// </summary>
private void PositionOnSecondaryScreen()
{
Screen secondaryScreen = null;
if (Screen.AllScreens.Length == 1)
{
secondaryScreen = Screen.PrimaryScreen;
}
else
{
foreach (Screen screen in Screen.AllScreens)
{
if (screen.Primary == false)
{
secondaryScreen = screen;
break;
}
}
}
this.Location = secondaryScreen.WorkingArea.Location;
this.Size = secondaryScreen.WorkingArea.Size;
}
屏幕绘制字符其实很简单,就是在指定位置DrawString,但在绘制之前最好能MeasureString来测算要绘制的字符长度