| Using System; Using System.Collections.Generic; Using System.Linq; Using System.Text; Using System.Windows.Controls; Using System.ComponentModel; Using System.Drawing; Using System.Timers; Using System.Windows; Namespace Wpfdemonew.control { <summary> Label Merry-go Custom Control </summary> [ToolboxBitmap (typeof (Label)]//Set icon displayed in Toolbox public class Scrollingtextcontrol:label { <summary> Timer </summary> Timer Marqueetimer = new timer (); <summary> Scrolling text source </summary> String _textsource = "scrolling text source"; <summary> Output text </summary> String _outtext = String. Empty; <summary> Scrolling speed of text </summary> Double _runspeed = 1000; ///<summary> / Constructor ///</summary> public Scrollingtextcontrol () { Marqueetimer.interval = _runspeed;//The speed of text movement marqueetimer.enabled = true; Turn on timed trigger event marqueetimer.elapsed + = new Elapsedeventhandler (marqueetimer_elapsed);//Bind timed event this. Loaded + = new Routedeventhandler (scrollingtextcontrol_loaded);//Bound Control Loaded event } void scrollingtextcontrol_loaded (object sender, RoutedEventArgs E ) { _textsource = setcontent; _outtext = _textsource + " "; } void Marqueetimer_elapsed (object sender, Elapsedeventargs e) { if (string. IsNullOrEmpty (_outtext)) return; _outtext = _outtext.substring (1) + _outtext[0]; Dispatcher.begininvoke (() The New Action (() => { SetContent = _outtext; })); } <summary> Speed of scrolling </summary> [Description (Speed of text scrolling)]//Show description in property Design view Public double Runspeed { get {return _runspeed;} Set { _runspeed = value; Marqueetimer.interval = _runspeed; } } ///<summary> / Scrolling text source ///</summary> [Description (Speed of text scrolling)] public string TextSource { get {return _textsource;} Set { _textsource = value; _outtext = _ TextSource; } } private String SetContent { get {return content.tostring ();} Set { Content = value; } } } } |