Our application in the past has used GoComment nodes with AutoResizes=true, but now I am switching to resizable GoBalloon nodes with AutoResizes=false.
The problem I have is when loading saved projects from the old version of my application. Because they used to be auto sized, we never saved the width and height of the GoComment.
Now I need to manually set the initial size for the GoBalloons on project load.
I can make it work by creating a temporary GoComment object that has AutoResizes set to true, putting the text into this temporary GoComment, and then using the width and height of this auto-sized temporary GoComment for my GoBalloon. But this seemed a little like a kludge (creating a temporary GoComment object just to get the auto size).
The manual calculations I tried were:
For the height:
// Get an array of individual lines, separated by CR/LF, so that we have
// a count of the total number of lines of text
string lines = goBalloon.Label.Text.String.Replace("\r\n","\n").Split('\n');
goBalloon.Label.Height = lines.Length * goBalloon.Label.Font.Height;
This height seems to be correct.
For the width:
goBalloon.Label.Width = System.Windows.Forms.TextRenderer.MeasureText(longestLineOfText, goBalloon.Label.Font).Width;
But this always comes out a little wider (12 to 20 pixels) than it did using AutoResizes, so there is more margin along the right of the text. I am not sure why it is wider by varying amounts using this calculation.
How should I calculate the width so that it is the same as it would be if AutoResizes=true.