SfButton AutoSize not woking well

Hello,

I have an SfButton with following options:

            this.sfButton1.AccessibleName = "Button";

            this.sfButton1.AutoSize = true;

            this.sfButton1.Font = new System.Drawing.Font("Segoe UI Semibold", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);

            this.sfButton1.Location = new System.Drawing.Point(164, 394);

            this.sfButton1.Name = "sfButton1";

            this.sfButton1.Padding = new System.Windows.Forms.Padding(7, 0, 7, 0);

            this.sfButton1.Size = new System.Drawing.Size(260, 28);

            this.sfButton1.Style.Image = global::NET.Properties.Resources.icon_logout_48;

            this.sfButton1.TabIndex = 10;

            this.sfButton1.Text = "sfButton1";

            this.sfButton1.UseVisualStyleBackColor = true;


When I type a larger text to Intellisense Text property, the control resize itself to the new width -> thats ok:


After that when I type smaller text than the previous, the width of the button not changing:


I think the button width in this case wrong, it should be smaller.

Can you help me please how can I set button autosize that depends on the width of the image + text + padding + margin? 

Thank you very much!

BR, SZL



5 Replies 1 reply marked as answer

BA BagavathiPerumal Apranandham Syncfusion Team August 17, 2022 02:08 PM UTC

Hi SZL,


We are able to reproduce the issue from my end. But even MS Button also behaves the same. Please refer the sample for your reference.



Regards,
Bagavathi Perumal A


Attachment: Button_6f646b64.zip


SZ SZL replied to BagavathiPerumal Apranandham August 17, 2022 02:17 PM UTC

Hi,

Thank you, I think the Microsoft should fix this. :) 

But for workaround I have an idea:

            button1.AutoSize = false;

            button1.Width = 5;

            button1.Text = "";

            button1.AutoSize = true;

            button1.Text = "small text";

With this the above problem fixed. 

Can you integrate a similar solution inside the SfButton code in the future or I should use this workaround everywhere?

Thank you!

BR, SZL


Marked as answer

BA BagavathiPerumal Apranandham Syncfusion Team August 18, 2022 12:49 PM UTC

Hi SZL,


We cannot include this workaround in our control, please use this workaround in the application.


Regards,

Bagavathi Perumal A



SZ SZL replied to BagavathiPerumal Apranandham August 18, 2022 03:01 PM UTC

Hi,

Ok, I created my custom control with this fix, it works well.

Thank you for help!


BR, SZL



GT Gokul Thanudhas Syncfusion Team August 19, 2022 02:39 PM UTC

Hi SZL,


We hope that your issue is resolved. Please let us know if you need any other assistance. We are happy to assist you.


Regards,

Gokul T


Loader.
Up arrow icon