Chr*_*jer 4 .net c# taskdialog
我注意到我的任务对话框中有一个大的垂直空间(命令链接标题和指令文本之间的空间)看起来非常糟糕.它在我将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();
Run Code Online (Sandbox Code Playgroud)
这是结果:

之前,"bar"会出现在"foo"的正下方,但现在看起来好像两者之间有一条空行.这是我的问题(并且有人会知道它可能是什么)或者你们也经历过这个问题吗?
我在1.1版本中遇到了同样的错误.这似乎是由于TaskDialogCommandLink类的toString方法string.Format有Environment.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);
}
Run Code Online (Sandbox Code Playgroud)
我总是使用一个实现子类来使参数更容易,并且过度使用方法来传递包含简单'\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;
}
Run Code Online (Sandbox Code Playgroud)