Hi all I am trying to make a scrolling text, but I cannot get it to scroll smoothly after the characters start to disappear.
this is my code:
if (outString.Length == 0)
{
for (int l = 0; l < m_horizontalText.Length; l++)
{
outString += m_horizontalText[l].ToString();
}
stringStart = 0;
fontSize = (m_horizontalText.Length) * m_font.Size;
startPosition = this.ClientSize.Width;
fo = new Font(m_font.FontFamily.Name, m_font.Size, GraphicsUnit.Pixel); g = this.CreateGraphics();
iWidth = g.MeasureString(m_horizontalText[stringStart].ToString(), fo).Width; // == 11
}
Point pt = new Point(startPosition, (this.ClientSize.Height / 2)); // Adds visible lines to path.
if (((pt.X + (int)iWidth) > (outString.Length * -1)))
{
if (startPosition <= ((int)iWidth * -1))
{
if (stringStart == m_horizontalText.Length)
{
stringStart = 0;
}
stringStart++;
outString = "";
startPosition += (int)iWidth;
//fo = new Font(m_font.FontFamily.Name, m_font.Size, GraphicsUnit.Pixel);
//g = this.CreateGraphics(); iWidth = g.MeasureString(m_horizontalText[stringStart].ToString(), fo).Width; // == 11
for (int l = stringStart; l < m_horizontalText.Length; l++)
{
outString += m_horizontalText[l].ToString();
}
}
path.AddString(outString, m_font.FontFamily, (int)m_font.Style, m_font.Size, pt, StringFormat.GenericTypographic);
}
startPosition--;
// For repeat scrolling.
if ((startPosition <= (startPosition * -1)) && (m_scrollingOffset < 0))
{
m_scrollingOffset = (int)(this.Font.SizeInPoints * outString.Length);
}
// Draws wrapped path. e.Graphics.FillPath(new SolidBrush(this.ForeColor), path);
path.Dispose();
the reason for using this method is that I need a transparent background and this is the only way I have found to achive this.
Thanks in advance,
Lee
ChrisPosted Mar 25, 2008, 12:35 PM
You should be drawing in the Paint event or OnPaint override of the form.
You should not really ever use CreateGraphics().
Please read my reply to this thread.
Once youve changed your code, to only pefrom drawing when Paint event is called,
try adding the following line to your form_load method
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint,true);