How to detect that the text has created new lines

Asked

Viewed 50 times

0

Let’s imagine I have a lable and has a text with n characters. Whenever this text does not fit he will put the words in the bottom line. How do I detect that this happened?

I tried so

    internal int ContarQuebrasLinhas()
    {
        return LBLNomeEvento.Text.Split('\n').Length;
    }

It works when I’m the one making that break

lable.Text = "aaaaa\naaaaa";

I will now show the image of how it would appear

inserir a descrição da imagem aqui

As it does not fit in the same line it does line breaking

  • But in this case the text did not create new lines... it is only being displayed with the break by container settings... the value remains unchanged.

  • Exactly. He does it automatically and I need to know when he does it

  • You can always try it that way: return LBLNomeEvento.Count(r => r == Environment.NewLine);.

  • @Joãomartins Enviroment.NewLine would not simply \r\n?

  • @Amadeuantunes, you may be able to compare the Height attribute of the label with the Actualheight... if the second is larger, there was line break and dividing by the initial, maybe you can estimate the number of lines

  • Include your label’s Markup in the question

  • @Leandroangelo yes, it’s the same thing! It’s the same habit :)

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.