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.
Niradhip ChakrabortyPosted Aug 1, 2008, 5:04 PM
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.
raja ramPosted Mar 9, 2009, 3:35 AM
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.
RevathiPosted Jan 20, 2009, 10:28 PM
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.