Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrolling text/marquee

Tags:

c#

text

wpf

I wanted to make a scrooling text that goes from right to left.There are some available on internet and used one of those.But soon realized that my text would be of two color and along with the scrolling text i would have to add imagees . this made it complicatedd.Any idea how it can be done.

My idea was to add Label(one color) image then label other color plus image into some stack panel or something and then move it some how.

i am beginner at wpf so i am unable to maky my way out

like image 526
Afnan Bashir Avatar asked Sep 14 '26 09:09

Afnan Bashir


1 Answers

As i understand from your question, I suggest you to user RichTextBox that you can easily paste image and text. For this purpose, you can do following steps:

  • Create your RichTextBox and add FlowDocument to it ( And also add Paragraph to this FlowDocument ) :

    NOTE: We will use this declared paragraph to add our text and images

    NOTE: You must to set PageWidth to a large number, because RichTextBox has not option to set TextWrapping ( like a TextWrapping option in TextBox ).

    <RichTextBox x:Name="RichTextBox1" Height="25">
            <FlowDocument x:Name="FlowDocument1" PageWidth="1000">
                    <Paragraph x:Name="Paragraph1">
                            Your Text Will Be Placed Here
                    </Paragraph>
            </FlowDocument>
    </RichTextBox>
    
  • You can add your own image to Paragraph by following code:

    Image img = new Image();
    img.Source = YourImageSource;
    img.Width = YourImageWidth;
    Paragraph1.Inlines.Add(img);
    
  • You can add your own colory text to Paragraph with code as follow :

    string YourText = "ColoryText";
    Paragraph1.Inlines.Add(new Run(YourText) { Foreground = Brushes.Blue });
    
  • Now, it is enough to declare a Timer from System.Timers.Timer and work with Elapsed Event.

like image 115
Hossein Mobasher Avatar answered Sep 17 '26 00:09

Hossein Mobasher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!