Click here to Skip to main content
15,908,020 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to implement scrolling text(marquee) functionality in winforms for rtf in c#. I need text to scroll from bottom to top. and loop back..
I have done this using scrollbar..but dont know how to repeat or loop

Please give some suggestions..
Posted
Comments
BillWoodruff 31-Jan-14 6:38am    
Are you asking how you can make a RichTextBox Control move up and down in a Form ?

1 solution

Call the following in a timer. Set startTime to the time you started the timer.
C#
private void TimerCalledMethod()
{
    TimeSpan runningSpan = DateTime.Now - startTime;
    float cycleFraction = runningSpan % timeSpanForOneCycle;    // Or convert both to milliseconds

    float scrollFraction;
    if (cycleFraction < 0.5F)
    {
        scrollFraction = 2F * cycleFraction;
    }
    else
    // cycleFraction must be between 0.5 and 1
    {
        scrollFraction = 2F - (2F * cycleFraction);
    }

    ScrollBar.SetPosition(rtfHeight * scrollFraction);
}


[Edit]That's untested pseudo-code just coincidentally looking much like C#.[/Edit]
 
Share this answer
 
v2
Comments
srini45 31-Jan-14 4:53am    
Thanks for the reply


private void TimerCalledMethod()
{
TimeSpan runningSpan = DateTime.Now - startTime;
float cycleFraction = runningSpan % timeSpanForOneCycle; // Or convert both to milliseconds

float scrollFraction;
if (cycleFraction < 0.5F)
{
scrollFraction = 2F * cycleFraction;
}
else
// cycleFraction must be between 0.5 and 1
{
scrollFraction = 2F - (2F * cycleFraction);
}

ScrollBar.SetPosition(rtfHeight * scrollFraction);
}


I am getting following error..
ScrollBar.SetPosition SetPosition doesnot exist in scrollbar..

What is the mistake..

Please help
lukeer 31-Jan-14 8:58am    
MSDN[^] is your friend here. It states that the Value[^] property is used to set a ScrollBar's position.

And please don't post code in comments. It's much more readable when posted within the question enclosed in tags as such: <pre lang="cs">YourCodeHere();</pre>.
You can still change your question using the green Improve question[^] link just beneath your question.
srini45 31-Jan-14 5:28am    
Here is the entire code..please help..

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace ScrollVertically
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "RTF Files|*.rtf";
if (ofd.ShowDialog() == DialogResult.OK)
{
richTextBox1.LoadFile(ofd.FileName);
}
}

private void button2_Click(object sender, EventArgs e)
{
timer1.Enabled = true;

Stopwatch stopWatch = Stopwatch.StartNew();
stopWatch.Stop();
DateTime time = DateTime.Now;
TimeSpan runningSpan = DateTime.Now - time;

float cycleFraction = 1000 % 100; // Or convert both to milliseconds

float scrollFraction;
if (cycleFraction < 0.5F)
{
scrollFraction = 2F * cycleFraction;
}
else
// cycleFraction must be between 0.5 and 1
{
scrollFraction = 2F - (2F * cycleFraction);
}

ScrollBar.SetPosition(richTextBox1.Height * scrollFraction);
}
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900