Unplanned
Last Updated: 23 May 2025 09:12 by Pascal
Pascal
Created on: 16 May 2025 09:36
Category: TextBoxControl
Type: Bug Report
0
Wrong AutoSize of TextBoxElement inside TextBoxControl when AutoSize enabled also on parent Form

When enabling AutoSize on all RadTextBoxControl elements on a Form and the Form has its AutoSize porperty set to True, then the size of the TextBoxElement inside the TextBox autosizes wrong. See the pictures. This happens at runtime and under specific conditions also at design time.

If you change Form.AutoSize to False OR at least ONE RadTextBoxControl to AutoSize = False then everything works as normal. But if ALL RadTextBoxControl has AutoSize to True and The Form.AutoSize is True, then this happens.

Office 2019:

Windows 11 Compact:

5 comments
Pascal
Posted on: 23 May 2025 09:12

Hello Dinko,

thank you very much for your review and response!

Yea true, this mostly happens if the RadTextBoxControl is not the only column (or specifically not the first column).

For reference, I replaced all the RadTextBoxes with RadTextBoxControl after I needed to use them at a few points. As it's a native TPF control, it has a themed and cusotmizeable context menu. The highlight color looks more modern and some few other details. Using both different TextBoxes lead to an inconsistent design (due size, context menu, visual difference) I wanted to avoid. Also I want to ensure I can fully access the features of a RadTextBoxControl when I need them without replacing it before. I see the RadTextBox is perfectly for migrating projects, but like to replace those with the most native RadTextBoxControl after some time and build new applications directly with it.

Also, I'm using full AutoSize on most flyouts and dialogs as a customizeable sizing is absolutely not requierd and mostly not inteted here. Only the main form or specific other forms are not AutoSize and fully cusotmizeable.

Looking fordward for possible fixes in the future. :)

Wish you a nice day!

Best regards,
Pascal

ADMIN
Dinko | Tech Support Engineer
Posted on: 22 May 2025 13:53

Hello Pascal,

I appreciate the provided details and sharing your progress on investigating this behavior. 

In general, the RadTextBoxControl is not designed to be AutoSize. The control is expected to have a specific size or to take the size of its parent. In the attached project, everything is AutoSize. This way, the RadTextBoxControl does not know how much space to take, thus leading to this sharing behavior.

The RadTextBoxControl has its own implementation and custom items inside. While the RadTextBox hosts the MS TextBox control. The size mechanism comes from the MS TextBox control, and in such scenarios, it behaves much better than the RadTextBoxControl. Is there a specific reason to replace all RadTextBoxes with RadTextBoxControl? 

In your project, if you set the AutoSize to false, remove the Size property and set the Dock to Fill of the RadTextBoxControls, you can observe that the controls are sized correctly. Their size in this scenario comes from the RadLabels. The parent TableLayoutPanel set the size of the second column by calculating the size of the labels and leaving the rest space. This will give a size for the RadTextBoxControl. However, if we remove the labels, both controls will be shrunk. In general, working with AutoSize is a little bit tricky due to different corner cases.

I have discussed this with the development team and we agree that we could improve how the RadTextBoxControl behaves in the AutoSize scenario. I have changed the status of the item to Unplanned. You can follow the feedback item to receive status notification changes.

Your Telerik Points are updated for the provided information and for the project isolating this behavior.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Pascal
Posted on: 20 May 2025 06:46

I know this fix will only work for the if RadTextBoxControl is part of a fully AutoSized Form. As soon as the Form is AutoSize=false it will not work anymore.

Tried to rewrite the patch, but honestly I miss one parameter for indication at this point. That means the issue is at Size calculation somewhere probably.

However, I hope this all infos help you to find the root issue.

Thank you very much. :)

[HarmonyPatch("ProcessAutoSizeChanged")]
[HarmonyPatch(typeof(RadTextBoxControl))]
internal class MyPatch
{
    public static void Postfix(bool value, object __instance)
    {
        if (__instance is not RadTextBoxControl @this)
            return;
        var found = false;
        var parent = @this.Parent;
        while (parent != null)
        {
            if (!parent.AutoSize)
            {
                found = true;
                break;
            }
            parent = parent.Parent;
        }
        @this.RootElement.StretchVertically = value && !found /*&& ???*/;
        @this.RootElement.SaveCurrentStretchModeAsDefault();
    }
}

Pascal
Posted on: 20 May 2025 05:43

I think I found the root cause of this. The method overwrite in "RadTextBoxControl" for "ProcessAutoSizeChanged()" sets  the "RootElement.StretchVertically" property to "false" whenever AutoSize is enabled.

Possible solution: When you comment out this line of code then the RadTextBoxControl autosizes normally.

I wrote a harmony patch to explicitely ignore this line. It works fine!

Not sure why this line is neccessery but I'm sure there is an intention behind. However, I need to ignore this line to be able to use RadTextBoxControl as full drop-in replacement in all my dialogs.

Possible (real) solution -> Add a static property like "RadTextBoxControl.AutoStretchOnAutoSize" that can be disabled on program start, if required. If disabled, the overwrite method "SaveCurrentStretchModeAsDefault()" would just do nothing.

Pascal
Posted on: 19 May 2025 03:53
Another example at runtime:


This came up after migrating all RadTextBox controls to RadTextBoxControl controls and enable AutoSize like it was on RadTextBox and how it is required for the layout to size completely automatically.