dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.29k stars 957 forks source link

Can't remove tooltip once added to NumericUpDown #11417

Closed deerchao closed 1 month ago

deerchao commented 1 month ago

.NET version

8.0.4

Did it work in .NET Framework?

No

Did it work in any of the earlier releases of .NET Core or .NET 5+?

I don't think so.

Issue description

var f = new Form();
var n = new NumericUpDown(); // can't realy clear tooltip once set
// var n = new TextBox();    // we can clear tooltip
var t = new ToolTip();
var b = new Button { Left = 100, Top = 50, Text = "Clear"};
b.Click += (_, _) => t.SetToolTip(n, null);

f.Controls.Add(n);
f.Controls.Add(b);

t.SetToolTip(n, "haha ha");

f.ShowDialog();

Once tooltip set on NumericUpDown, it can't be cleared. In this sample, After click the clear button, tooltip removed on textbox but not on numericupdown.

Steps to reproduce

Create a winforms app, set tooltip to numericupdown, try to clear the tooltip, and you will see it doesn't work.

It was shocking to find out this issue exists in .net framework, too.

elachlan commented 1 month ago

@Olina-Zhang can your team please test this?

Olina-Zhang commented 1 month ago

Yes, can repro it with .Net and .Net framework versions. Repro with NumericUpDown and DomainUpDown, but not in others: TextBox/DateTimePicker/Button

.NET 9.0/.NET8.0 and .NET Framework 4.6.2/4.8.1 have same behavior:

https://github.com/dotnet/winforms/assets/26474449/2f676385-7843-440c-bbc6-17c798a7e109

elachlan commented 1 month ago

I think this is because of UpDownBase.SetToolTip. It looks like it calls SetToolTip for its "Child" controls. https://github.com/dotnet/winforms/blob/9014e5968c858b7375b0150a1d099716435d9f5f/src/System.Windows.Forms/src/System/Windows/Forms/Controls/UpDown/UpDownBase.cs#L975-L985

It looks like the corresponding UpDownBase.RemoveToolTip is not implemented to cleanup. I am unsure if its a memory leak.

MandiMan commented 1 month ago

Verified this issue on 9.0.100-preview.6.24278.19 with dlls built from winforms repo of main branch, it was fixed: after click the clear button, tooltips removed on NumericUpDown and DomainUpDown.

https://github.com/dotnet/winforms/assets/108860782/a3f3a853-ead9-485a-b0ef-3ef8fc3c5773

Zheng-Li01 commented 1 week ago

Verified the issue with .NET 9.0.100-preivew6.24325.8 TP build. the issue has been fixed that have the same results as above.