Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic ResizeToFitText moving box down when EnableStyledText set to true (Read 260 times)
David Long
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 153
Location: England
Joined: Oct 23rd, 2006
ResizeToFitText moving box down when EnableStyledText set to true
Jan 16th, 2026 at 12:16pm
Print Post  
I have just tried setting both EnableStyledText and PolygonalTextLayout to true for the boxes in my chart.

While editing chart boxes, I resize the temporary edit control and the box in question to fit the newly entered text. With the above two variables set to true, the temporary edit control and chart box both move down the screen as I enter characters. This does not happen with these variables set to false.

On investigation, the ResizeToFitText function changes the Y position of box it is called on. This did not happen before. My code looks like this...

protected void TextBox_TextChanged(object sender, EventArgs e)
{
Debug.Print("Edited box bounds = " + EditedBox.Bounds.X + " " + EditedBox.Bounds.Y);

using var tempBox = new ShapeNode(EditedBox);
tempBox.Text = TempEditControl.Text;

// If text ends with a 'New Line', add something onto the end of the text otherwise
// the top line is lost

if (tempBox.Text.EndsWith(Environment.NewLine, StringComparison.OrdinalIgnoreCase))
tempBox.Text += "Abc123";

tempBox.ResizeToFitText(FitSize.KeepWidth);
Debug.Print("After ResizeToFitText - tempBox bounds = " + tempBox.Bounds.X + " " + tempBox.Bounds.Y);

EditedBox.Bounds = tempBox.Bounds;

var clientRect = FlowChartView.DocToClient(tempBox.Bounds);

TempEditControl.Location = clientRect.Location;
TempEditControl.Size = clientRect.Size;

Debug.Print("--------------------------------------");
}

Is this a bug? Is there a work-around I can use.

Regards
DavidL
« Last Edit: Jan 19th, 2026 at 2:02pm by David Long »  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3435
Joined: Oct 19th, 2005
Re: ResizeToFitText moving box down when EnableStyledText set to true
Reply #1 - Jan 19th, 2026 at 11:37am
Print Post  
Hi,

We'll review it for next release. At this time you could call tempBox.Move(EditedBox.Bounds.X, EditedBox.Bounds.Y) after calling ResizeTiFit method, and before assigning Bounds back to EditedBox;

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
David Long
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 153
Location: England
Joined: Oct 23rd, 2006
Re: ResizeToFitText moving box down when EnableStyledText set to true
Reply #2 - Jan 19th, 2026 at 2:04pm
Print Post  
Sorry I missed your reply before adding some text to the original post. I said...

I have got around the problem by saving and restoring the original Y position of the box being edited, so no big issue.

However, new issue...

Is it possible to have a version of ResizeToFitText that takes into account the bold, italic and underline tags such as <b> </b>. With the current version and bold, italic and underlined text, the above code will produce an edit box that does not fit all the characters.

DavidL
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3435
Joined: Oct 19th, 2005
Re: ResizeToFitText moving box down when EnableStyledText set to true
Reply #3 - Jan 19th, 2026 at 3:30pm
Print Post  
If you mean you need to resize the TextBox edit control to fit all raw tags, ShapeNode.ResizeToFit could help only if you disable styled text rendering on the tempBox (so it's not rendering bold text but shows <b> and </b> elements for example) and also possibly change the ShapeNode.Shape to Rectangle if it's a different one. Otherwise there's no 1:1 correspondence between text strings in the node and edit control, and ResizeToFitText' resulting size will be for different strings altogether.

Instead of creating a temporary node to measure text size, you might as well try using WinForms' TextRenderer to decide the TextBox' size, as TextRenderer should be a closer match to TextBox' internal rendering:

Code
Select All
void ResizeMultilineTextBox(TextBox textBox)
{
    textBox.Multiline = true;

    var size = TextRenderer.MeasureText(
        textBox.Text,
        textBox.Font,
        new Size(textBox.Width, int.MaxValue),
        TextFormatFlags.WordBreak);

    textBox.Height = size.Height; // some padding might be needed
} 



Regards,
Slavcho
MindFusion
  
Back to top
 
IP Logged
 
David Long
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 153
Location: England
Joined: Oct 23rd, 2006
Re: ResizeToFitText moving box down when EnableStyledText set to true
Reply #4 - Jan 20th, 2026 at 10:59am
Print Post  
Thanks, that is very helpful.  This is the final version if it helps anyone. The TextFormatFlags.TextBoxControl seemed to be very necessary and I have set a minimum height...

private void ResizeMultilineTextBox(DragTextBox textBox)
{
    string textToMeasure = textBox.Text;

    if (textBox.Text.EndsWith(Environment.NewLine, StringComparison.OrdinalIgnoreCase))
        textToMeasure += "Abc123";

    var size = TextRenderer.MeasureText(textToMeasure,
                                        textBox.Font,
                                        new Size(textBox.Width, int.MaxValue),
                                        TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl);

    var minBoxHeight = FlowChartView.DocToClient(EditedBox.Bounds).Height;

    if (size.Height < minBoxHeight)
        textBox.Height = minBoxHeight;
    else
        textBox.Height = size.Height;
}
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint