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> ...
随机推荐
- Windows平台CUDA开发之前的准备工作
CUDA是NVIDIA的GPU开发工具,眼下在大规模并行计算领域有着广泛应用. windows平台上面的CUDA开发之前.最好去NVIDIA官网查看说明,然后下载对应的driver. ToolKits ...
- Linux 系统挂载数据盘 分类: B3_LINUX 2015-01-30 18:13 228人阅读 评论(0) 收藏
适用系统:Linux(Redhat , CentOS,Debian,Ubuntu) * Linux的云服务器数据盘未做分区和格式化,可以根据以下步骤进行分区以及格式化操作. 下面的操作将会把数据盘划 ...
- 贝叶斯统计(Bayesian statistics) vs 频率统计(Frequentist statistics):marginal likelihood(边缘似然)
1. Bayesian statistics 一组独立同分布的数据集 X=(x1,-,xn)(xi∼p(xi|θ)),参数 θ 同时也是被另外分布定义的随机变量 θ∼p(θ|α),此时: p(X|α) ...
- 该扩展程序未列在 Chrome 网上应用店中,并可能是在您不知情的情况下添加的
"chrome扩展程序无法启用"的解决方案 http://www.cnplugins.com/tool/installpluginfix.html win10家庭版没有组策略怎么办? https:// ...
- [CSS] Design for Mobile First with Tachyons
Tachyons provides extensions (-ns, -m, and -l) to many of its classes to help you design for respons ...
- ios开发缓存处理类NSCash类的了解与使用
一:NSCash的基本了解 #import "ViewController.h" @interface ViewController ()<NSCacheDelegate&g ...
- NYOJ 364 田忌赛马
田忌赛马 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描写叙述 Here is a famous story in Chinese history. "That ...
- [Compose] 18. Maintaining structure whilst asyncing
We take our Promise.all() analogy further by using traversable on a Map(). Then we use two traversal ...
- JNI:no implementation found in native...
一 javah引发的问题 BUG:D/dalvikvm( 1704): Trying to load lib /data/data/com.ulang/lib/libulangaudio.so 0x ...
- php资源集
php资源集 一.php资源网站 1.php中文网(js特效,模板,软件工具下载,课程) www.php.cn js特效下载_js特效代码_js特效大全-php中文网免费下载站http://www.p ...