C# Forms: Different text size of label and DrawString

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dzenanz
    New Member
    • Feb 2008
    • 45

    C# Forms: Different text size of label and DrawString

    Platform: VS2005/WinXP/.NET 2.0

    I am trying to make one sentence of text scroll from right to left over the form (that works well enough, although not perfect).
    Problem is, when I try to add shadow to that text, shadow (drawn with DrawString in OnPaint event) is a bit wider, and it accumulates over time.
    Left edge of a shadow is not where it should be - it is more to the left then it should be.


    Also, as the whole thing moves to the left, it leaves a nasty trail behind (on the right).


    Code:
    private void panel1_Paint(object sender, PaintEventArgs e)
    {
        e.Graphics.DrawString(label1.Text, label1.Font,
            new System.Drawing.SolidBrush(Color.FromArgb(64, label1.ForeColor)),
            label1.Left + 1, label1.Top + 1);//try changing these to 5 or 10
    }
    
    private void timer1_Tick(object sender, EventArgs e)
    {
        if (label1.Left + label1.Width < 0)
            label1.Left = panel1.Width;
        else
            label1.Left -= 1;
    }
    As you probably guess, this is just simplified problem in a larger project...
Working...