gpt4 book ai didi

c# - 如何在文本框上显示气球提示?

转载 作者:可可西里 更新时间:2023-11-01 08:21:04 24 4
gpt4 key购买 nike

我有一个使用 XAML 和 MVVM 的 C# WPF 应用程序。我的问题是:对于用户输入的某些无效数据,如何在文本框上方显示气球工具提示?

我想使用微软的 native balloon control为了这。我将如何在我的应用程序中实现它?

最佳答案

只需添加对 System.Windows.FormsC:\Program Files\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\WindowsFormsIntegration.dll 的引用然后:

    WindowsFormsHost host =new WindowsFormsHost();

var toolTip1 = new System.Windows.Forms.ToolTip();

toolTip1.AutoPopDelay = 5000;
toolTip1.InitialDelay = 1000;
toolTip1.ReshowDelay = 500;
toolTip1.ShowAlways = true;
toolTip1.IsBalloon = true;
toolTip1.ToolTipIcon = System.Windows.Forms.ToolTipIcon.Info;
toolTip1.ToolTipTitle = "Title:";

System.Windows.Forms.TextBox tb = new System.Windows.Forms.TextBox();
tb.Text="Go!";
toolTip1.SetToolTip(tb, "My Info!");
host.Child = tb;
grid1.Children.Add(host); //a container for windowsForm textBox

这是 WPF 中的 WinForm ToolTip Ballon 示例:

enter image description here

希望对您有所帮助!

关于c# - 如何在文本框上显示气球提示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7541767/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com