WPF 走马灯 文字滚动 自定义控件
/// <summary>
/// Label走马灯自定义控件
/// </summary>
[ToolboxBitmap(typeof(Label))] //设置工具箱中显示的图标
public class ScrollingTextControl : Label
{
/// <summary>
/// 定时器
/// </summary>
Timer MarqueeTimer = new Timer();
/// <summary>
/// 滚动文字源
/// </summary>
String _TextSource = "滚动文字源";
/// <summary>
/// 输出文本
/// </summary>
String _OutText = string.Empty;
/// <summary>
/// 过度文本存储
/// </summary>
string _TempString = string.Empty;
/// <summary>
/// 文字的滚动速度
/// </summary>
double _RunSpeed = ; DateTime _SignTime;
bool _IfFirst = true; /// <summary>
/// 滚动一循环字幕停留的秒数,单位为毫秒,默认值停留3秒
/// </summary>
int _StopSecond = ; /// <summary>
/// 滚动一循环字幕停留的秒数,单位为毫秒,默认值停留3秒
/// </summary>
public int StopSecond
{
get { return _StopSecond; }
set
{
_StopSecond = value;
}
} /// <summary>
/// 滚动的速度
/// </summary>
[Description("文字滚动的速度")] //显示在属性设计视图中的描述
public double RunSpeed
{
get { return _RunSpeed; }
set
{
_RunSpeed = value;
MarqueeTimer.Interval = _RunSpeed;
}
} /// <summary>
/// 滚动文字源
/// </summary>
[Description("文字滚动的Text")]
public string TextSource
{
get { return _TextSource; }
set
{
_TextSource = value;
_TempString = _TextSource + " ";
_OutText = _TempString;
}
} private string SetContent
{
get { return Content.ToString(); }
set
{
Content = value;
}
} /// <summary>
/// 构造函数
/// </summary>
public ScrollingTextControl()
{
MarqueeTimer.Interval = _RunSpeed;//文字移动的速度
MarqueeTimer.Enabled = true; //开启定时触发事件
MarqueeTimer.Elapsed += new ElapsedEventHandler(MarqueeTimer_Elapsed);//绑定定时事件
this.Loaded += new RoutedEventHandler(ScrollingTextControl_Loaded);//绑定控件Loaded事件
} void ScrollingTextControl_Loaded(object sender, RoutedEventArgs e)
{
_TextSource = SetContent;
_TempString = _TextSource + " ";
_OutText = _TempString;
_SignTime = DateTime.Now;
} void MarqueeTimer_Elapsed(object sender, ElapsedEventArgs e)
{
if (string.IsNullOrEmpty(_OutText)) return; if (_OutText.Substring() + _OutText[] == _TempString)
{
if (_IfFirst)
{
_SignTime = DateTime.Now;
} if ((DateTime.Now - _SignTime).TotalMilliseconds > _StopSecond)
{
_IfFirst = true; ;
}
else
{
_IfFirst = false;
return;
}
} _OutText = _OutText.Substring() + _OutText[]; Dispatcher.BeginInvoke(new Action(() =>
{
SetContent = _OutText;
})); } }
以上放到cs文件中 然后 编译 就可以在工具箱中看到ScrollingTextControl 名称的label控件
<Window x:Class="WpfDemoNew.Window21"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window21" Height="300" Width="300" xmlns:my="clr-namespace:WpfDemoNew.Control">
<Grid x:Name="grid">
<my:ScrollingTextControl Content="12345" Height="52" HorizontalAlignment="Left" Margin="10,10,0,0" x:Name="scrollingTextControl1" VerticalAlignment="Top" Width="121" Foreground="Black" />
</Grid>
</Window>
WPF 走马灯 文字滚动 自定义控件的更多相关文章
- 单行文字滚动就用myslider
单行文字滚动就用myslider,myslider是一个小型的内容滚动jquery插件. 首先请看实例:http://keleyi.com/jq/myslider/demo/4.htm 然后来看代码: ...
- winfrom 文字滚动
winfrom 文字滚动 http://www.codeproject.com/Articles/6913/Creating-a-professional-looking-GDI-drawn-cust ...
- marquee 标签 文字滚动
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- js鼠标经过文字滚动,移开还原
不说别的,直接贴代码. <div class="kj-scroll" id="countrylist0" onmouseover="wPAa = ...
- marquee|各种文字滚动代码(适用公告)
marquee|各种文字滚动代码(适用公告)
- Unity3D 文字滚动跑马灯效果
需求 在日常游戏中,文字滚动效果是比较常用的.例如日常游戏顶部的新闻公告,聊天系统的文字滚动,都属于这个范围. 思路 由于使用的地方比较广泛,所以希望能够尽量独立的游戏之外,能够做到随处使用的功能.N ...
- WPF checkbox文字下掉
WPF checkbox文字下掉 可以使用 <Style TargetType="CheckBox"> <Setter Property="Margin ...
- section标签实现文字滚动
h5新增样式 section标签 使用demo //h5新增属性 h5新增滚动的标签 <marquee> <div style="padding-left: 20px;ma ...
- HTML之marquee(文字滚动)详解
语法: <marquee></marquee> 以下是一个最简单的例子: 代码如下: <marquee><font size=+3 color=red> ...
随机推荐
- 教你写Http框架(二)——三个样例带你深入理解AsyncTask
这个标题大家不要奇怪,扯Http框架怎么扯到AsyncTask去了,有两个原因:首先是Http框架除了核心http理论外.其技术实现核心也是线程池 + 模板 + handler,而AsyncTask又 ...
- php实现矩形覆盖
php实现矩形覆盖 一.总结 很简单的斐波那契数列 二.php实现矩形覆盖 题目描述: 我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形.请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总 ...
- Pandoc —— 标记语言转换工具(中文乱码问题)
今次毕业设计,来个逼格高的,用 latex 编写.谁曾想,学院首先要收一份 word 版的.辣么多的 latex 公式如何转呀. Pandoc 是由 John MacFarlane 开发的标记语言转换 ...
- [SCSS] Write similar classes with the SCSS @for Control Directive
Writing similar classes with minor variations, like utility classes, can be a pain to write and upda ...
- jquery ajax实现省市二级联动
今天给大家带来使用jQuery ajax实现的省市联动效果.我们直奔主题,先说下实现思路: 准备数据 这里数据库我使用的是mysql,先看下表格: provience表 city表 这里使用provi ...
- [转载]Ocelot简易教程(三)之主要特性及路由详解
上篇<Ocelot简易教程(二)之快速开始2>教大家如何快速跑起来一个ocelot实例项目,也只是简单的对Ocelot进行了配置,这篇文章会给大家详细的介绍一下Ocelot的配置信息.希望 ...
- Springmvc+Shiro实战
原文链接:http://blog.csdn.net/qq_37936542/article/details/79010449 springmvc+shiro实现系统粗细粒度的权限管理步骤: 1:表格设 ...
- 【u017】请柬
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 在电视时代,没有多少人观看戏剧表演.Malidinesia古董喜剧演员意识到这一事实,他们想宣传剧院, ...
- Cocos2d-x 3.2 Lua演示样例FontTest(字体測试)
Cocos2d-x 3.2 Lua演示样例FontTest(字体測试) 本篇博客介绍Cocos2d-x 3.2中Lua測试项目中的FontTest样例,主要使用了字体文件来创建我们想要的字体样式: 第 ...
- Ubuntu,右键->在终端中打开(apt-install,或者手动增加右键菜单)
方法一: sudo apt-get install nautilus-open-terminal 然后重启 方法二: Ubuntu中,默认右键菜单中没有“在终端中打开”.要想添加此菜单,可以在主目录中 ...