Skip to content

Desktop News Ticker

wajid ansari

Asked Aug 1, 2008, 10:49 AM EDTSolved
Share
LinkedInX

Hi Friends

 Does any one have code to develop desktop news ticker in c# or else please send me any helpfull link to develope the same. I need a scrolling links on my desptop  and when any of the link is clicked, it should navigate to that particular page.  Thanks in advance.

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Niradhip Chakraborty
    ✓ Accepted answer+1
    Check Out the  custom control that implements a news ticker.  Add a new class to your project, then paste this code:

    using System;
    using System.Text;
    using System.Drawing;
    using System.ComponentModel;
    using System.Windows.Forms;

    class NewsTicker : Panel {
      private Timer mScroller;    // Scroll timer
      private int mOffset;        // Offset of scrolled text
      private string mText;       // Text to scroll
      private Size mPixels;       // Width of text in pixels
      private Bitmap mBuffer;     // Double-buffering buffer

      public NewsTicker() {
        mScroller = new Timer();
        mScroller.Interval = 30;
        mScroller.Enabled = false;
        mScroller.Tick += DoScroll;
      }
      [Browsable(true)]
      public override string Text {
        get { return mText; }
        set {
          mText = value;
          mScroller.Enabled = mText.Length > 0;
          mPixels = TextRenderer.MeasureText(mText, this.Font);
          mOffset = this.Width;
        }
      }
      private void DoScroll(object sender, EventArgs e) {
        // Adjust offset and paint
        mOffset -= 1;
        if (mOffset < -mPixels.Width) mOffset = this.Width;
        Invalidate();
      }
      protected override void OnPaintBackground(PaintEventArgs e) {
        // Do nothing
      }
      protected override void OnPaint(PaintEventArgs e) {
        if (mBuffer == null || mBuffer.Width != this.Width || mBuffer.Height != this.Height)
          mBuffer = new Bitmap(this.Width, this.Height);
        Graphics gr = Graphics.FromImage(mBuffer);
        Brush bbr = new SolidBrush(this.BackColor);
        Brush fbr = new SolidBrush(this.ForeColor);
        gr.FillRectangle(bbr, new Rectangle(0, 0, this.Width, this.Height));
        gr.DrawString(mText, this.Font, fbr, mOffset, 0);
        e.Graphics.DrawImage(mBuffer, 0, 0);
        bbr.Dispose();
        fbr.Dispose();
        gr.Dispose();
      }
    }

    Build the project, then drop a NewsTicker from the Toolbox onto the form.  Set the Text property in the designer and the text should immediately start ticking.
    +1
  • +1

    Hi,

    The solution provided works great. I just have some trouble displaying the ticker news in different color. For example some urgent news need to be displayed in red while the rest in a different color within the same ticker.

    Really hope someone can guide me on this. Thanks alot in advance. 

    +1
  • +1

    Hi,

     I have gone through the code. its works perfectly fine. But when i am trying to conver the same in vb.net, But its not working. Please provide me the same in VB.Net.

    +1