asp.net WPF merry-go text scrolling custom control

Source: Internet
Author: User

The code is as follows Copy Code

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;
}
}
}
}

The above is placed in the CS file and then compiled to see the Scrollingtextcontrol name Label control in the Toolbox

The code is as follows Copy Code

<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=" "Width=" 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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.