I have created a user control on winform where i want to display some text on Label Control at runtime. Here I used textFormatFlag as WordBreak and then displays it in the next line. Size of label is fixed in width while variable in height. Now the problem here is how to break a string if there is no space between i.e. no WordBreak Present in the string. I dont want to do calculations on font size and accordingly modify string. Is it something hidden in .net that can do this work for me.
sizeCategory = TextRenderer.MeasureText(Source["Parent_Name"].ToString()
, lbldbCategory.Font
, sizeCategory
, TextFormatFlags.WordBreak);
Consider lines as a boundary of my label. width height. Height being variable. Consider this eg.
My text string being
"salkdjasldjkslakdjlsakjdlsakjdkajhk sdjahksajd" //see word break between the string
-----------------------------------------------|
salkdjasldjkslakdjlsakjdlsakjdkajhk |
sdjahksajd |
-----------------------------------------------|
What I did and currently getting is this.
due to word break
-----------------------------------------------|
salkdjasldjkslakdjlsakjdlsakjd |
kajhksdjahksajdh |
-----------------------------------------------|
What is happening is when string has no space i.e. no word break
-----------------------------------------------|
salkdjasldjkslakdjlsakjdlsakjdkajhksdjahksajdhasdasdasdsadasd|
-----------------------------------------------|
What I want is
-----------------------------------------------|
salkdjasldjkslakdjlsakjdlsakjdkajhksdjahksajdha|
sdasdasdsadasd |
-----------------------------------------------|