1

The following code is not painting anything:

void Form3_Paint(object sender, PaintEventArgs e)
{
      string text = new string('m', 3000);
      TextRenderer.DrawText(
          e.Graphics,
          text,
          this.Font,
          new Point(10, 10),
          Color.Black,
          Color.Transparent);
}

Seems that the string is too long. If I change the string lenght to 2000 it works (I'm using SegoeUI 9) font.

Do you know any workaround for this?

Daniel Peñalba
  • 30,507
  • 32
  • 137
  • 219
  • that's a lot of characters for one line. Draw text i have only seen it used to draw one line at a time using single or double space for multiple display. Anyhow try using `.DrawString()` instead. – Franck Sep 19 '14 at 11:00
  • 1
    What? You asked the same question 1 year ago and asking again? Seriously? Are you kidding? Probably can we expect same question next year? – Sriram Sakthivel Sep 19 '14 at 11:14
  • Maybe this is a yearly ritual for him? – Uğur Aldanmaz Sep 20 '14 at 10:45

1 Answers1

1

I try your code block and it painted. So I increment the string length up to 4401. After that my test failed too.

Probably TextRender.DrawText method has a limitation on string. But I think that this limitation should be depended on machine.

You want to a workaround. So I suggest that Graphics.DrawString method.

string text = new string('m', 4401);
            e.Graphics.DrawString(text,
                this.Font,
                Brushes.Black,
                new Point(0, 0)
                );

Edited

Oh! I searched this issue and I found this question on stackoverflow.

TextRenderer doesn't draw a long string

What a coincidence! You asked same issue before 1 year ago.

Community
  • 1
  • 1
Uğur Aldanmaz
  • 1,018
  • 1
  • 11
  • 16