gpt4 book ai didi

c# - 自 v1.1 以来,TaskDialog 中命令链接中的垂直空间

转载 作者:太空狗 更新时间:2023-10-30 00:42:01 24 4
gpt4 key购买 nike

我注意到我的任务对话框中有一个很大的垂直空间(命令链接的标题和说明文本之间的空间),看起来非常糟糕。它在我将 WindowsAPICodePack 升级到 1.1 版后立即开始出现。

代码如下:

TaskDialog td = new TaskDialog();
var b1 = new TaskDialogCommandLink("b1", "foo", "bar");
var b2 = new TaskDialogCommandLink("b2", "one", "two");
td.Controls.Add(b1);
td.Controls.Add(b2);
td.Caption = "Caption";
td.InstructionText = "InstructionText";
td.Text = "Text";
td.Show();

结果如下:

Ugly task dialog with vertical space in command links

以前,“bar”会出现在“foo”的正下方,但现在看起来两者之间好像有一个空行。这是我的问题吗(有人知道它可能是什么吗)还是你们也遇到了这个问题?

最佳答案

我在 1.1 版本中遇到了同样的错误。这似乎是由于 TaskDialogCommandLink 类的 toString 方法 string.FormatEnvironment.NewLine,它不传递给 TaskDialog 本身时,不会干净地映射。

public override string ToString()
{
return string.Format(CultureInfo.CurrentCulture, "{0}{1}{2}",
Text ?? string.Empty,
(!string.IsNullOrEmpty(Text) && !string.IsNullOrEmpty(instruction)) ?
Environment.NewLine : string.Empty,
instruction ?? string.Empty);
}

无论如何我都使用一个实现子类来使参数更容易,并且覆盖了传递包含简单'\n'的字符串的方法,尽管我不需要国际化我的应用程序所以可以做一些事情更简单。

public override string ToString()
{
string str;

bool noLabel = string.IsNullOrEmpty(this.Text);
bool noInstruction = string.IsNullOrEmpty(this.Instruction);

if (noLabel & noInstruction)
{
str = string.Empty;
}
else if (!noLabel & noInstruction)
{
str = this.Text;
}
else if (noLabel & !noInstruction)
{
str = base.Instruction;
}
else
{
str = this.Text + "\n" + this.Instruction;
}
return str;
}

关于c# - 自 v1.1 以来,TaskDialog 中命令链接中的垂直空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17716544/

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